qwindow.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qwindow.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
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 The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qwindow.h"-
41-
42#include <qpa/qplatformwindow.h>-
43#include <qpa/qplatformintegration.h>-
44#include "qsurfaceformat.h"-
45#ifndef QT_NO_OPENGL-
46#include <qpa/qplatformopenglcontext.h>-
47#include "qopenglcontext.h"-
48#endif-
49#include "qscreen.h"-
50-
51#include "qwindow_p.h"-
52#include "qguiapplication_p.h"-
53#ifndef QT_NO_ACCESSIBILITY-
54# include "qaccessible.h"-
55#endif-
56#include "qhighdpiscaling_p.h"-
57-
58#include <private/qevent_p.h>-
59-
60#include <QtCore/QTimer>-
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{Raster Window Example} and \l{OpenGL Window Example}-
82 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 QWindow::Visibility queried through visibility() is a convenience API-
119 combining the functions of visible() and windowState().-
120-
121 \section1 Rendering-
122-
123 There are two Qt APIs that can be used to render content into a window,-
124 QBackingStore for rendering with a QPainter and flushing the contents-
125 to a window with type QSurface::RasterSurface, and QOpenGLContext for-
126 rendering with OpenGL to a window with type QSurface::OpenGLSurface.-
127-
128 The application can start rendering as soon as isExposed() returns \c true,-
129 and can keep rendering until it isExposed() returns \c false. To find out when-
130 isExposed() changes, reimplement exposeEvent(). The window will always get-
131 a resize event before the first expose event.-
132-
133 \section1 Initial Geometry-
134-
135 If the window's width and height are left uninitialized, the window will-
136 get a reasonable default geometry from the platform window. If the position-
137 is left uninitialized, then the platform window will allow the windowing-
138 system to position the window. For example on X11, the window manager-
139 usually does some kind of smart positioning to try to avoid having new-
140 windows completely obscure existing windows. However setGeometry()-
141 initializes both the position and the size, so if you want a fixed size but-
142 an automatic position, you should call resize() or setWidth() and-
143 setHeight() instead.-
144*/-
145-
146/*!-
147 Creates a window as a top level on the \a targetScreen.-
148-
149 The window is not shown until setVisible(true), show(), or similar is called.-
150-
151 \sa setScreen()-
152*/-
153QWindow::QWindow(QScreen *targetScreen)-
154 : QObject(*new QWindowPrivate(), 0)-
155 , QSurface(QSurface::Window)-
156{-
157 Q_D(QWindow);-
158 d->connectToScreen(targetScreen ? targetScreen : QGuiApplication::primaryScreen());-
159 d->init();-
160}-
161-
162/*!-
163 Creates a window as a child of the given \a parent window.-
164-
165 The window will be embedded inside the parent window, its coordinates-
166 relative to the parent.-
167-
168 The screen is inherited from the parent.-
169-
170 \sa setParent()-
171*/-
172QWindow::QWindow(QWindow *parent)-
173 : QObject(*new QWindowPrivate(), parent)-
174 , QSurface(QSurface::Window)-
175{-
176 Q_D(QWindow);-
177 d->parentWindow = parent;-
178 if (!parent)-
179 d->connectToScreen(QGuiApplication::primaryScreen());-
180 d->init();-
181}-
182-
183/*!-
184 Creates a window as a child of the given \a parent window with the \a dd-
185 private implementation.-
186-
187 The window will be embedded inside the parent window, its coordinates-
188 relative to the parent.-
189-
190 The screen is inherited from the parent.-
191-
192 \internal-
193 \sa setParent()-
194*/-
195QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)-
196 : QObject(dd, parent)-
197 , QSurface(QSurface::Window)-
198{-
199 Q_D(QWindow);-
200 d->parentWindow = parent;-
201 if (!parent)-
202 d->connectToScreen(QGuiApplication::primaryScreen());-
203 d->init();-
204}-
205-
206/*!-
207 Destroys the window.-
208*/-
209QWindow::~QWindow()-
210{-
211 destroy();-
212 QGuiApplicationPrivate::window_list.removeAll(this);-
213 if (!QGuiApplicationPrivate::is_app_closing)-
214 QGuiApplicationPrivate::instance()->modalWindowList.removeOne(this);-
215}-
216-
217void QWindowPrivate::init()-
218{-
219 Q_Q(QWindow);-
220-
221 // If your application aborts here, you are probably creating a QWindow-
222 // before the screen list is populated.-
223 if (Q_UNLIKELY(!parentWindow && !topLevelScreen))) {
__builtin_expe...creen), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
224 qFatal("Cannot create window: no screens available");-
225 exit(1);
never executed: exit(1);
0
226 }-
227 QGuiApplicationPrivate::window_list.prepend(q);-
228-
229 requestedFormat = QSurfaceFormat::defaultFormat();-
230}
never executed: end of block
0
231-
232/*!-
233 \enum QWindow::Visibility-
234 \since 5.1-
235-
236 This enum describes what part of the screen the window occupies or should-
237 occupy.-
238-
239 \value Windowed The window occupies part of the screen, but not necessarily-
240 the entire screen. This state will occur only on windowing systems which-
241 support showing multiple windows simultaneously. In this state it is-
242 possible for the user to move and resize the window manually, if-
243 WindowFlags permit it and if it is supported by the windowing system.-
244-
245 \value Minimized The window is reduced to an entry or icon on the task bar,-
246 dock, task list or desktop, depending on how the windowing system handles-
247 minimized windows.-
248-
249 \value Maximized The window occupies one entire screen, and the titlebar is-
250 still visible. On most windowing systems this is the state achieved by-
251 clicking the maximize button on the toolbar.-
252-
253 \value FullScreen The window occupies one entire screen, is not resizable,-
254 and there is no titlebar. On some platforms which do not support showing-
255 multiple simultaneous windows, this can be the usual visibility when the-
256 window is not hidden.-
257-
258 \value AutomaticVisibility This means to give the window a default visible-
259 state, which might be fullscreen or windowed depending on the platform.-
260 It can be given as a parameter to setVisibility but will never be-
261 read back from the visibility accessor.-
262-
263 \value Hidden The window is not visible in any way, however it may remember-
264 a latent visibility which can be restored by setting AutomaticVisibility.-
265*/-
266-
267/*!-
268 \property QWindow::visibility-
269 \brief the screen-occupation state of the window-
270 \since 5.1-
271-
272 Visibility is whether the window should appear in the windowing system as-
273 normal, minimized, maximized, fullscreen or hidden.-
274-
275 To set the visibility to AutomaticVisibility means to give the window-
276 a default visible state, which might be fullscreen or windowed depending on-
277 the platform.-
278 When reading the visibility property you will always get the actual state,-
279 never AutomaticVisibility.-
280*/-
281QWindow::Visibility QWindow::visibility() const-
282{-
283 Q_D(const QWindow);-
284 return d->visibility;-
285}-
286-
287void QWindow::setVisibility(Visibility v)-
288{-
289 switch (v) {-
290 case Hidden:-
291 hide();-
292 break;-
293 case AutomaticVisibility:-
294 show();-
295 break;-
296 case Windowed:-
297 showNormal();-
298 break;-
299 case Minimized:-
300 showMinimized();-
301 break;-
302 case Maximized:-
303 showMaximized();-
304 break;-
305 case FullScreen:-
306 showFullScreen();-
307 break;-
308 default:-
309 Q_ASSERT(false);-
310 break;-
311 }-
312}-
313-
314void QWindowPrivate::updateVisibility()-
315{-
316 Q_Q(QWindow);-
317-
318 QWindow::Visibility old = visibility;-
319-
320 if (visible) {-
321 switch (windowState) {-
322 case Qt::WindowMinimized:-
323 visibility = QWindow::Minimized;-
324 break;-
325 case Qt::WindowMaximized:-
326 visibility = QWindow::Maximized;-
327 break;-
328 case Qt::WindowFullScreen:-
329 visibility = QWindow::FullScreen;-
330 break;-
331 case Qt::WindowNoState:-
332 visibility = QWindow::Windowed;-
333 break;-
334 default:-
335 Q_ASSERT(false);-
336 break;-
337 }-
338 } else {-
339 visibility = QWindow::Hidden;-
340 }-
341-
342 if (visibility != old)-
343 emit q->visibilityChanged(visibility);-
344}-
345-
346inline bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen) const-
347{-
348 Q_Q(const QWindow);-
349 const QScreen *oldScreen = q->screen();-
350 return oldScreen != newScreen && (platformWindow || !oldScreen)-
351 && !(oldScreen && oldScreen->virtualSiblings().contains(newScreen));-
352}-
353-
354inline void QWindowPrivate::disconnectFromScreen()-
355{-
356 if (topLevelScreen)-
357 topLevelScreen = 0;-
358}-
359-
360void QWindowPrivate::connectToScreen(QScreen *screen)-
361{-
362 disconnectFromScreen();-
363 topLevelScreen = screen;-
364}-
365-
366void QWindowPrivate::emitScreenChangedRecursion(QScreen *newScreen)-
367{-
368 Q_Q(QWindow);-
369 emit q->screenChanged(newScreen);-
370 foreachfor (QObject *child ,: q->children()) {-
371 if (child->isWindowType())
child->isWindowType()Description
TRUEnever evaluated
FALSEnever evaluated
0
372 static_cast<QWindow *>(child)->d_func()->emitScreenChangedRecursion(newScreen);
never executed: static_cast<QWindow *>(child)->d_func()->emitScreenChangedRecursion(newScreen);
0
373 }
never executed: end of block
0
374}
never executed: end of block
0
375-
376void QWindowPrivate::setTopLevelScreen(QScreen *newScreen, bool recreate)-
377{-
378 Q_Q(QWindow);-
379 if (parentWindow) {-
380 qWarning() << q << '(' << newScreen << "): Attempt to set a screen on a child window.";-
381 return;-
382 }-
383 if (newScreen != topLevelScreen) {-
384 const bool shouldRecreate = recreate && windowRecreationRequired(newScreen);-
385 const bool shouldShow = visibilityOnDestroy && !topLevelScreen;-
386 if (shouldRecreate && platformWindow)-
387 q->destroy();-
388 connectToScreen(newScreen);-
389 if (shouldShow)-
390 q->setVisible(true);-
391 else if (newScreen && shouldRecreate)-
392 create(true);-
393 emitScreenChangedRecursion(newScreen);-
394 }-
395}-
396-
397void QWindowPrivate::create(bool recursive)-
398{-
399 Q_Q(QWindow);-
400 if (platformWindow)
platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
401 return;
never executed: return;
0
402-
403 if (q->parent())
q->parent()Description
TRUEnever evaluated
FALSEnever evaluated
0
404 q->parent()->create();
never executed: q->parent()->create();
0
405-
406 platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(q);-
407 Q_ASSERT(platformWindow || q->type() == Qt::ForeignWindow);-
408-
409 if (!platformWindow) {
!platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
410 qWarning() << "Failed to create platform window for" << q << "with flags" << q->flags();-
411 return;
never executed: return;
0
412 }-
413-
414 QObjectList childObjects = q->children();-
415 for (int i = 0; i < childObjects.size(); i ++) {
i < childObjects.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
416 QObject *object = childObjects.at(i);-
417 if ((!object->isWindowType())
!object->isWindowType()Description
TRUEnever evaluated
FALSEnever evaluated
0
418 {continue;
never executed: continue;
0
419-
420 QWindow *windowchildWindow = static_cast<QWindow *>(object);-
421 if (recursive)
recursiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
422 windowchildWindow->d_func()->create(recursive);
never executed: childWindow->d_func()->create(recursive);
0
423-
424 // The child may have had deferred creation due to this window not being created-
425 // at the time setVisible was called, so we re-apply the visible state, which-
426 // may result in creating the child, and emitting the appropriate signals.-
427
childWindow->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
if (childWindow->isVisible())
childWindow->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
428 childWindow->setVisible
never executed: childWindow->setVisible(true);
(true);
never executed: childWindow->setVisible(true);
0
429-
430 if (windowQPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
QPlatformWindo...platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
431 window->d_func()->platformWindowchildPlatformWindow->setParent(this->platformWindow);
never executed: childPlatformWindow->setParent(this->platformWindow);
0
432 }}
never executed: end of block
0
433-
434 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);-
435 QGuiApplication::sendEvent(q, &e);-
436}
never executed: end of block
0
437-
438void QWindowPrivate::clearFocusObject()-
439{-
440}-
441-
442// Allows for manipulating the suggested geometry before a resize/move-
443// event in derived classes for platforms that support it, for example to-
444// implement heightForWidth().-
445QRectF QWindowPrivate::closestAcceptableGeometry(const QRectF &rect) const-
446{-
447 Q_UNUSED(rect)-
448 return QRectF();-
449}-
450-
451/*!-
452 Sets the \a surfaceType of the window.-
453-
454 Specifies whether the window is meant for raster rendering with-
455 QBackingStore, or OpenGL rendering with QOpenGLContext.-
456-
457 The surfaceType will be used when the native surface is created-
458 in the create() function. Calling this function after the native-
459 surface has been created requires calling destroy() and create()-
460 to release the old native surface and create a new one.-
461-
462 \sa QBackingStore, QOpenGLContext, create(), destroy()-
463*/-
464void QWindow::setSurfaceType(SurfaceType surfaceType)-
465{-
466 Q_D(QWindow);-
467 d->surfaceType = surfaceType;-
468}-
469-
470/*!-
471 Returns the surface type of the window.-
472-
473 \sa setSurfaceType()-
474*/-
475QWindow::SurfaceType QWindow::surfaceType() const-
476{-
477 Q_D(const QWindow);-
478 return d->surfaceType;-
479}-
480-
481/*!-
482 \property QWindow::visible-
483 \brief whether the window is visible or not-
484-
485 This property controls the visibility of the window in the windowing system.-
486-
487 By default, the window is not visible, you must call setVisible(true), or-
488 show() or similar to make it visible.-
489-
490 \sa show()-
491*/-
492void QWindow::setVisible(bool visible)-
493{-
494 Q_D(QWindow);-
495-
496 if (d->visible ==!= visible) return;{
d->visible != visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
497 d->visible = visible;-
498 emit visibleChanged(visible);-
499 d->updateVisibility();-
500 } else if (d->platformWindow) {
never executed: end of block
d->platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
501 // Visibility hasn't changed, and the platform window is in sync-
502
never executed: return;
return;
never executed: return;
0
503 }-
504-
505 if (!d->platformWindow) {
!d->platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
506 // If we have a parent window, but the parent hasn't been created yet, we-
507 // can defer creation until the parent is created or we're re-parented.-
508
parent()Description
TRUEnever evaluated
FALSEnever evaluated
!parent()->handle()Description
TRUEnever evaluated
FALSEnever evaluated
if (parent() && !parent()->handle())
parent()Description
TRUEnever evaluated
FALSEnever evaluated
!parent()->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
509 return;
never executed: return;
0
510 else-
511 create();
never executed: create();
0
512 }-
513-
514 if (visible) {
visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
515 // remove posted quit events when showing a new window-
516 QCoreApplication::removePostedEvents(qApp, QEvent::Quit);-
517-
518 if (type() == Qt::Window) {
type() == Qt::WindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
519 QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance();-
520 QString &firstWindowTitle = app_priv->firstWindowTitle;-
521 if (!firstWindowTitle.isEmpty()) {
!firstWindowTitle.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
522 setTitle(firstWindowTitle);-
523 firstWindowTitle = QString();-
524 }
never executed: end of block
0
525 if (!app_priv->forcedWindowIcon.isNull())
!app_priv->for...wIcon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
526 setIcon(app_priv->forcedWindowIcon);
never executed: setIcon(app_priv->forcedWindowIcon);
0
527-
528 // Handling of the -qwindowgeometry, -geometry command line arguments-
529 static bool geometryApplied = false;-
530 if (!geometryApplied) {
!geometryAppliedDescription
TRUEnever evaluated
FALSEnever evaluated
0
531 geometryApplied = true;-
532 QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(this);-
533 }
never executed: end of block
0
534 }
never executed: end of block
0
535-
536 QShowEvent showEvent;-
537 QGuiApplication::sendEvent(this, &showEvent);-
538 }
never executed: end of block
0
539-
540 if (isModal()) {
isModal()Description
TRUEnever evaluated
FALSEnever evaluated
0
541 if (visible)
visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
542 QGuiApplicationPrivate::showModalWindow(this);
never executed: QGuiApplicationPrivate::showModalWindow(this);
0
543 else-
544 QGuiApplicationPrivate::hideModalWindow(this);
never executed: QGuiApplicationPrivate::hideModalWindow(this);
0
545 }-
546-
547#ifndef QT_NO_CURSOR-
548 if (visible && (d->hasCursor || QGuiApplication::overrideCursor()))
visibleDescription
TRUEnever evaluated
FALSEnever evaluated
d->hasCursorDescription
TRUEnever evaluated
FALSEnever evaluated
QGuiApplicatio...errideCursor()Description
TRUEnever evaluated
FALSEnever evaluated
0
549 d->applyCursor();
never executed: d->applyCursor();
0
550#endif-
551-
552 d->platformWindow->setVisible(visible);-
553-
554 if (!visible) {
!visibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
555 QHideEvent hideEvent;-
556 QGuiApplication::sendEvent(this, &hideEvent);-
557 }
never executed: end of block
0
558}
never executed: end of block
0
559-
560bool QWindow::isVisible() const-
561{-
562 Q_D(const QWindow);-
563-
564 return d->visible;-
565}-
566-
567/*!-
568 Allocates the platform resources associated with the window.-
569-
570 It is at this point that the surface format set using setFormat() gets resolved-
571 into an actual native surface. However, the window remains hidden until setVisible() is called.-
572-
573 Note that it is not usually necessary to call this function directly, as it will be implicitly-
574 called by show(), setVisible(), and other functions that require access to the platform-
575 resources.-
576-
577 Call destroy() to free the platform resources if necessary.-
578-
579 \sa destroy()-
580*/-
581void QWindow::create()-
582{-
583 Q_D(QWindow);-
584 d->create(false);-
585}-
586-
587/*!-
588 Returns the window's platform id.-
589-
590 For platforms where this id might be useful, the value returned-
591 will uniquely represent the window inside the corresponding screen.-
592-
593 \sa screen()-
594*/-
595WId QWindow::winId() const-
596{-
597 Q_D(const QWindow);-
598-
599 if (type() == Qt::ForeignWindow)-
600 return WId(property("_q_foreignWinId").value<WId>());-
601-
602 if(!d->platformWindow)-
603 const_cast<QWindow *>(this)->create();-
604-
605 return d->platformWindow->winId();-
606}-
607-
608/*!-
609 Returns the parent window, if any.-
610-
611 A window without a parent is known as a top level window.-
612*/-
613QWindow *QWindow::parent() const-
614{-
615 Q_D(const QWindow);-
616 return d->parentWindow;-
617}-
618-
619/*!-
620 Sets the \a parent Window. This will lead to the windowing system managing-
621 the clip of the window, so it will be clipped to the \a parent window.-
622-
623 Setting \a parent to be 0 will make the window become a top level window.-
624-
625 If \a parent is a window created by fromWinId(), then the current window-
626 will be embedded inside \a parent, if the platform supports it.-
627*/-
628void QWindow::setParent(QWindow *parent)-
629{-
630 Q_D(QWindow);-
631 if (d->parentWindow == parent)
d->parentWindow == parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
632 return;
never executed: return;
0
633-
634 QScreen *newScreen = parent ? parent->screen() : screen();
parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
635 if (d->windowRecreationRequired(newScreen)) {
d->windowRecre...red(newScreen)Description
TRUEnever evaluated
FALSEnever evaluated
0
636 qWarning() << this << '(' << parent << "): Cannot change screens (" << screen() << newScreen << ')';-
637 return;
never executed: return;
0
638 }-
639-
640 QObject::setParent(parent);-
641 d->parentWindow = parent;-
642-
643 if (parent)
parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
644 d->disconnectFromScreen();
never executed: d->disconnectFromScreen();
0
645 else-
646 d->connectToScreen(newScreen);
never executed: d->connectToScreen(newScreen);
0
647-
648 // If we were set visible, but not created because we were a child, and we're now-
649 // re-parented into a created parent, or to being a top level, we need re-apply the-
650 // visibility state, which will also create.-
651
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
!parentDescription
TRUEnever evaluated
FALSEnever evaluated
parent->handle()Description
TRUEnever evaluated
FALSEnever evaluated
if (isVisible() && (!parent || parent->handle()))
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
!parentDescription
TRUEnever evaluated
FALSEnever evaluated
parent->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
652 setVisible(true
never executed: setVisible(true);
);
never executed: setVisible(true);
0
653-
654 if (d->platformWindow) {
d->platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
655 if (parent&&)
parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
656 parent->d_func()->platformWindow) {create();
never executed: parent->create();
0
657-
658 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow);-
} else {
d->platformWindow ->setParent(: 0);
659 }}
never executed: end of block
0
660-
661 QGuiApplicationPrivate::updateBlockedStatus(this);-
662}
never executed: end of block
0
663-
664/*!-
665 Returns whether the window is top level, i.e. has no parent window.-
666*/-
667bool QWindow::isTopLevel() const-
668{-
669 Q_D(const QWindow);-
670 return d->parentWindow == 0;-
671}-
672-
673/*!-
674 Returns whether the window is modal.-
675-
676 A modal window prevents other windows from getting any input.-
677-
678 \sa QWindow::modality-
679*/-
680bool QWindow::isModal() const-
681{-
682 Q_D(const QWindow);-
683 return d->modality != Qt::NonModal;-
684}-
685-
686/*! \property QWindow::modality-
687 \brief the modality of the window-
688-
689 A modal window prevents other windows from receiving input events. Qt-
690 supports two types of modality: Qt::WindowModal and Qt::ApplicationModal.-
691-
692 By default, this property is Qt::NonModal-
693-
694 \sa Qt::WindowModality-
695*/-
696-
697Qt::WindowModality QWindow::modality() const-
698{-
699 Q_D(const QWindow);-
700 return d->modality;-
701}-
702-
703void QWindow::setModality(Qt::WindowModality modality)-
704{-
705 Q_D(QWindow);-
706 if (d->modality == modality)-
707 return;-
708 d->modality = modality;-
709 emit modalityChanged(modality);-
710}-
711-
712/*! \fn void QWindow::modalityChanged(Qt::WindowModality modality)-
713-
714 This signal is emitted when the Qwindow::modality property changes to \a modality.-
715*/-
716-
717/*!-
718 Sets the window's surface \a format.-
719-
720 The format determines properties such as color depth, alpha, depth and-
721 stencil buffer size, etc. For example, to give a window a transparent-
722 background (provided that the window system supports compositing, and-
723 provided that other content in the window does not make it opaque again):-
724-
725 \code-
726 QSurfaceFormat format;-
727 format.setAlphaBufferSize(8);-
728 window.setFormat(format);-
729 \endcode-
730-
731 The surface format will be resolved in the create() function. Calling-
732 this function after create() has been called will not re-resolve the-
733 surface format of the native surface.-
734-
735 When the format is not explicitly set via this function, the format returned-
736 by QSurfaceFormat::defaultFormat() will be used. This means that when having-
737 multiple windows, individual calls to this function can be replaced by one-
738 single call to QSurfaceFormat::setDefaultFormat() before creating the first-
739 window.-
740-
741 \sa create(), destroy(), QSurfaceFormat::setDefaultFormat()-
742*/-
743void QWindow::setFormat(const QSurfaceFormat &format)-
744{-
745 Q_D(QWindow);-
746 d->requestedFormat = format;-
747}-
748-
749/*!-
750 Returns the requested surface format of this window.-
751-
752 If the requested format was not supported by the platform implementation,-
753 the requestedFormat will differ from the actual window format.-
754-
755 This is the value set with setFormat().-
756-
757 \sa setFormat(), format()-
758 */-
759QSurfaceFormat QWindow::requestedFormat() const-
760{-
761 Q_D(const QWindow);-
762 return d->requestedFormat;-
763}-
764-
765/*!-
766 Returns the actual format of this window.-
767-
768 After the window has been created, this function will return the actual surface format-
769 of the window. It might differ from the requested format if the requested format could-
770 not be fulfilled by the platform. It might also be a superset, for example certain-
771 buffer sizes may be larger than requested.-
772-
773 \note Depending on the platform, certain values in this surface format may still-
774 contain the requested values, that is, the values that have been passed to-
775 setFormat(). Typical examples are the OpenGL version, profile and options. These may-
776 not get updated during create() since these are context specific and a single window-
777 may be used together with multiple contexts over its lifetime. Use the-
778 QOpenGLContext's format() instead to query such values.-
779-
780 \sa create(), requestedFormat(), QOpenGLContext::format()-
781*/-
782QSurfaceFormat QWindow::format() const-
783{-
784 Q_D(const QWindow);-
785 if (d->platformWindow)-
786 return d->platformWindow->format();-
787 return d->requestedFormat;-
788}-
789-
790/*!-
791 \property QWindow::flags-
792 \brief the window flags of the window-
793-
794 The window flags control the window's appearance in the windowing system,-
795 whether it's a dialog, popup, or a regular window, and whether it should-
796 have a title bar, etc.-
797-
798 The actual window flags might differ from the flags set with setFlags()-
799 if the requested flags could not be fulfilled.-
800*/-
801void QWindow::setFlags(Qt::WindowFlags flags)-
802{-
803 Q_D(QWindow);-
804 if (d->platformWindow)-
805 d->platformWindow->setWindowFlags(flags);-
806 d->windowFlags = flags;-
807}-
808-
809Qt::WindowFlags QWindow::flags() const-
810{-
811 Q_D(const QWindow);-
812 return d->windowFlags;-
813}-
814-
815/*!-
816 Returns the type of the window.-
817-
818 This returns the part of the window flags that represents-
819 whether the window is a dialog, tooltip, popup, regular window, etc.-
820-
821 \sa flags(), setFlags()-
822*/-
823Qt::WindowType QWindow::type() const-
824{-
825 Q_D(const QWindow);-
826 return static_cast<Qt::WindowType>(int(d->windowFlags & Qt::WindowType_Mask));-
827}-
828-
829/*!-
830 \property QWindow::title-
831 \brief the window's title in the windowing system-
832-
833 The window title might appear in the title area of the window decorations,-
834 depending on the windowing system and the window flags. It might also-
835 be used by the windowing system to identify the window in other contexts,-
836 such as in the task switcher.-
837-
838 \sa flags()-
839*/-
840void QWindow::setTitle(const QString &title)-
841{-
842 Q_D(QWindow);-
843 bool changed = false;-
844 if (d->windowTitle != title) {-
845 d->windowTitle = title;-
846 changed = true;-
847 }-
848 if (d->platformWindow && type() != Qt::Desktop)-
849 d->platformWindow->setWindowTitle(title);-
850 if (changed)-
851 emit windowTitleChanged(title);-
852}-
853-
854QString QWindow::title() const-
855{-
856 Q_D(const QWindow);-
857 return d->windowTitle;-
858}-
859-
860/*!-
861 \brief set the file name this window is representing.-
862-
863 The windowing system might use \a filePath to display the-
864 path of the document this window is representing in the tile bar.-
865-
866*/-
867void QWindow::setFilePath(const QString &filePath)-
868{-
869 Q_D(QWindow);-
870 d->windowFilePath = filePath;-
871 if (d->platformWindow)-
872 d->platformWindow->setWindowFilePath(filePath);-
873}-
874-
875/*!-
876 \brief the file name this window is representing.-
877-
878 \sa setFilePath()-
879*/-
880QString QWindow::filePath() const-
881{-
882 Q_D(const QWindow);-
883 return d->windowFilePath;-
884}-
885-
886/*!-
887 \brief Sets the window's \a icon in the windowing system-
888-
889 The window icon might be used by the windowing system for example to-
890 decorate the window, and/or in the task switcher.-
891*/-
892void QWindow::setIcon(const QIcon &icon)-
893{-
894 Q_D(QWindow);-
895 d->windowIcon = icon;-
896 if (d->platformWindow)-
897 d->platformWindow->setWindowIcon(icon);-
898 QEvent e(QEvent::WindowIconChange);-
899 QCoreApplication::sendEvent(this, &e);-
900}-
901-
902/*!-
903 \brief Sets the window's icon in the windowing system-
904-
905 \sa setIcon()-
906*/-
907QIcon QWindow::icon() const-
908{-
909 Q_D(const QWindow);-
910 if (d->windowIcon.isNull())-
911 return QGuiApplication::windowIcon();-
912 return d->windowIcon;-
913}-
914-
915/*!-
916 Raise the window in the windowing system.-
917-
918 Requests that the window be raised to appear above other windows.-
919*/-
920void QWindow::raise()-
921{-
922 Q_D(QWindow);-
923 if (d->platformWindow)-
924 d->platformWindow->raise();-
925}-
926-
927/*!-
928 Lower the window in the windowing system.-
929-
930 Requests that the window be lowered to appear below other windows.-
931*/-
932void QWindow::lower()-
933{-
934 Q_D(QWindow);-
935 if (d->platformWindow)-
936 d->platformWindow->lower();-
937}-
938-
939/*!-
940 \property QWindow::opacity-
941 \brief The opacity of the window in the windowing system.-
942 \since 5.1-
943-
944 If the windowing system supports window opacity, this can be used to fade the-
945 window in and out, or to make it semitransparent.-
946-
947 A value of 1.0 or above is treated as fully opaque, whereas a value of 0.0 or below-
948 is treated as fully transparent. Values inbetween represent varying levels of-
949 translucency between the two extremes.-
950-
951 The default value is 1.0.-
952*/-
953void QWindow::setOpacity(qreal level)-
954{-
955 Q_D(QWindow);-
956 if (level == d->opacity)-
957 return;-
958 d->opacity = level;-
959 if (d->platformWindow) {-
960 d->platformWindow->setOpacity(level);-
961 emit opacityChanged(level);-
962 }-
963}-
964-
965qreal QWindow::opacity() const-
966{-
967 Q_D(const QWindow);-
968 return d->opacity;-
969}-
970-
971/*!-
972 Sets the mask of the window.-
973-
974 The mask is a hint to the windowing system that the application does not-
975 want to receive mouse or touch input outside the given \a region.-
976-
977 The window manager may or may not choose to display any areas of the window-
978 not included in the mask, thus it is the application's responsibility to-
979 clear to transparent the areas that are not part of the mask.-
980-
981 Setting the mask before the window has been created has no effect.-
982*/-
983void QWindow::setMask(const QRegion &region)-
984{-
985 Q_D(QWindow);-
986 if (!d->platformWindow)-
987 return;-
988 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region, this));-
989 d->mask = region;-
990}-
991-
992/*!-
993 Returns the mask set on the window.-
994-
995 The mask is a hint to the windowing system that the application does not-
996 want to receive mouse or touch input outside the given region.-
997*/-
998QRegion QWindow::mask() const-
999{-
1000 Q_D(const QWindow);-
1001 return d->mask;-
1002}-
1003-
1004/*!-
1005 Requests the window to be activated, i.e. receive keyboard focus.-
1006-
1007 \sa isActive(), QGuiApplication::focusWindow(), QWindowsWindowFunctions::setWindowActivationBehavior()-
1008*/-
1009void QWindow::requestActivate()-
1010{-
1011 Q_D(QWindow);-
1012 if (flags() & Qt::WindowDoesNotAcceptFocus) {-
1013 qWarning() << "requestActivate() called for " << this << " which has Qt::WindowDoesNotAcceptFocus set.";-
1014 return;-
1015 }-
1016 if (d->platformWindow)-
1017 d->platformWindow->requestActivateWindow();-
1018}-
1019-
1020/*!-
1021 Returns if this window is exposed in the windowing system.-
1022-
1023 When the window is not exposed, it is shown by the application-
1024 but it is still not showing in the windowing system, so the application-
1025 should minimize rendering and other graphical activities.-
1026-
1027 An exposeEvent() is sent every time this value changes.-
1028-
1029 \sa exposeEvent()-
1030*/-
1031bool QWindow::isExposed() const-
1032{-
1033 Q_D(const QWindow);-
1034 return d->exposed;-
1035}-
1036-
1037/*!-
1038 \property QWindow::active-
1039 \brief the active status of the window-
1040 \since 5.1-
1041-
1042 \sa requestActivate()-
1043*/-
1044-
1045/*!-
1046 Returns \c true if the window should appear active from a style perspective.-
1047-
1048 This is the case for the window that has input focus as well as windows-
1049 that are in the same parent / transient parent chain as the focus window.-
1050-
1051 To get the window that currently has focus, use QGuiApplication::focusWindow().-
1052*/-
1053bool QWindow::isActive() const-
1054{-
1055 Q_D(const QWindow);-
1056 if (!d->platformWindow)-
1057 return false;-
1058-
1059 QWindow *focus = QGuiApplication::focusWindow();-
1060-
1061 // Means the whole application lost the focus-
1062 if (!focus)-
1063 return false;-
1064-
1065 if (focus == this)-
1066 return true;-
1067-
1068 if (!parent() && !transientParent()) {-
1069 return isAncestorOf(focus);-
1070 } else {-
1071 return (parent() && parent()->isActive()) || (transientParent() && transientParent()->isActive());-
1072 }-
1073}-
1074-
1075/*!-
1076 \property QWindow::contentOrientation-
1077 \brief the orientation of the window's contents-
1078-
1079 This is a hint to the window manager in case it needs to display-
1080 additional content like popups, dialogs, status bars, or similar-
1081 in relation to the window.-
1082-
1083 The recommended orientation is QScreen::orientation() but-
1084 an application doesn't have to support all possible orientations,-
1085 and thus can opt to ignore the current screen orientation.-
1086-
1087 The difference between the window and the content orientation-
1088 determines how much to rotate the content by. QScreen::angleBetween(),-
1089 QScreen::transformBetween(), and QScreen::mapBetween() can be used-
1090 to compute the necessary transform.-
1091-
1092 The default value is Qt::PrimaryOrientation-
1093*/-
1094void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)-
1095{-
1096 Q_D(QWindow);-
1097 if (d->contentOrientation == orientation)-
1098 return;-
1099 if (d->platformWindow)-
1100 d->platformWindow->handleContentOrientationChange(orientation);-
1101 d->contentOrientation = orientation;-
1102 emit contentOrientationChanged(orientation);-
1103}-
1104-
1105Qt::ScreenOrientation QWindow::contentOrientation() const-
1106{-
1107 Q_D(const QWindow);-
1108 return d->contentOrientation;-
1109}-
1110-
1111/*!-
1112 Returns the ratio between physical pixels and device-independent pixels-
1113 for the window. This value is dependent on the screen the window is on,-
1114 and may change when the window is moved.-
1115-
1116 Common values are 1.0 on normal displays and 2.0 on Apple "retina" displays.-
1117-
1118 \note For windows not backed by a platform window, meaning that create() was not-
1119 called, the function will fall back to QGuiApplication::devicePixelRatio() which in-
1120 turn returns the highest screen device pixel ratio found on the system.-
1121-
1122 \sa QScreen::devicePixelRatio(), QGuiApplication::devicePixelRatio()-
1123*/-
1124qreal QWindow::devicePixelRatio() const-
1125{-
1126 Q_D(const QWindow);-
1127-
1128 // If there is no platform window use the app global devicePixelRatio,-
1129 // which is the the highest devicePixelRatio found on the system-
1130 // screens, and will be correct for single-display systems (a very common case).-
1131 if (!d->platformWindow)-
1132 return qApp->devicePixelRatio();-
1133-
1134 return d->platformWindow->devicePixelRatio() * QHighDpiScaling::factor(this);-
1135}-
1136-
1137/*!-
1138 \brief set the screen-occupation state of the window-
1139-
1140 The window \a state represents whether the window appears in the-
1141 windowing system as maximized, minimized, fullscreen, or normal.-
1142-
1143 The enum value Qt::WindowActive is not an accepted parameter.-
1144-
1145 \sa showNormal(), showFullScreen(), showMinimized(), showMaximized()-
1146*/-
1147void QWindow::setWindowState(Qt::WindowState state)-
1148{-
1149 if (state == Qt::WindowActive) {
state == Qt::WindowActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
1150 qWarning() << ("QWindow::setWindowState does not accept Qt::WindowActive";);-
1151 return;
never executed: return;
0
1152 }-
1153-
1154 Q_D(QWindow);-
1155 if (d->platformWindow)
d->platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1156 d->platformWindow->setWindowState(state);
never executed: d->platformWindow->setWindowState(state);
0
1157 d->windowState = state;-
1158 emit windowStateChanged(d->windowState);-
1159 d->updateVisibility();-
1160}
never executed: end of block
0
1161-
1162/*!-
1163 \brief the screen-occupation state of the window-
1164-
1165 \sa setWindowState()-
1166*/-
1167Qt::WindowState QWindow::windowState() const-
1168{-
1169 Q_D(const QWindow);-
1170 return d->windowState;-
1171}-
1172-
1173/*!-
1174 \fn QWindow::windowStateChanged(Qt::WindowState windowState)-
1175-
1176 This signal is emitted when the \a windowState changes, either-
1177 by being set explicitly with setWindowState(), or automatically when-
1178 the user clicks one of the titlebar buttons or by other means.-
1179*/-
1180-
1181/*!-
1182 Sets the transient \a parent-
1183-
1184 This is a hint to the window manager that this window is a dialog or pop-up-
1185 on behalf of the given window.-
1186-
1187 In order to cause the window to be centered above its transient parent by-
1188 default, depending on the window manager, it may also be necessary to call-
1189 setFlags() with a suitable \l Qt::WindowType (such as \c Qt::Dialog).-
1190-
1191 \sa transientParent(), parent()-
1192*/-
1193void QWindow::setTransientParent(QWindow *parent)-
1194{-
1195 Q_D(QWindow);-
1196 if (parent && !parent->isTopLevel()) {-
1197 qWarning() << parent << "must be a top level window.";-
1198 return;-
1199 }-
1200-
1201 d->transientParent = parent;-
1202-
1203 QGuiApplicationPrivate::updateBlockedStatus(this);-
1204}-
1205-
1206/*!-
1207 Returns the transient parent of the window.-
1208-
1209 \sa setTransientParent(), parent()-
1210*/-
1211QWindow *QWindow::transientParent() const-
1212{-
1213 Q_D(const QWindow);-
1214 return d->transientParent.data();-
1215}-
1216-
1217/*!-
1218 \enum QWindow::AncestorMode-
1219-
1220 This enum is used to control whether or not transient parents-
1221 should be considered ancestors.-
1222-
1223 \value ExcludeTransients Transient parents are not considered ancestors.-
1224 \value IncludeTransients Transient parents are considered ancestors.-
1225*/-
1226-
1227/*!-
1228 Returns \c true if the window is an ancestor of the given \a child. If \a mode-
1229 is IncludeTransients, then transient parents are also considered ancestors.-
1230*/-
1231bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const-
1232{-
1233 if (child->parent() == this || (mode == IncludeTransients && child->transientParent() == this))-
1234 return true;-
1235-
1236 return (child->parent() && isAncestorOf(child->parent(), mode))-
1237 || (mode == IncludeTransients && child->transientParent() && isAncestorOf(child->transientParent(), mode));-
1238}-
1239-
1240/*!-
1241 Returns the minimum size of the window.-
1242-
1243 \sa setMinimumSize()-
1244*/-
1245QSize QWindow::minimumSize() const-
1246{-
1247 Q_D(const QWindow);-
1248 return d->minimumSize;-
1249}-
1250-
1251/*!-
1252 Returns the maximum size of the window.-
1253-
1254 \sa setMaximumSize()-
1255*/-
1256QSize QWindow::maximumSize() const-
1257{-
1258 Q_D(const QWindow);-
1259 return d->maximumSize;-
1260}-
1261-
1262/*!-
1263 Returns the base size of the window.-
1264-
1265 \sa setBaseSize()-
1266*/-
1267QSize QWindow::baseSize() const-
1268{-
1269 Q_D(const QWindow);-
1270 return d->baseSize;-
1271}-
1272-
1273/*!-
1274 Returns the size increment of the window.-
1275-
1276 \sa setSizeIncrement()-
1277*/-
1278QSize QWindow::sizeIncrement() const-
1279{-
1280 Q_D(const QWindow);-
1281 return d->sizeIncrement;-
1282}-
1283-
1284/*!-
1285 Sets the minimum size of the window.-
1286-
1287 This is a hint to the window manager to prevent resizing below the specified \a size.-
1288-
1289 \sa setMaximumSize(), minimumSize()-
1290*/-
1291void QWindow::setMinimumSize(const QSize &size)-
1292{-
1293 Q_D(QWindow);-
1294 QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));-
1295 if (d->minimumSize == adjustedSize)-
1296 return;-
1297 QSize oldSize = d->minimumSize;-
1298 d->minimumSize = adjustedSize;-
1299 if (d->platformWindow && isTopLevel())-
1300 d->platformWindow->propagateSizeHints();-
1301 if (d->minimumSize.width() != oldSize.width())-
1302 emit minimumWidthChanged(d->minimumSize.width());-
1303 if (d->minimumSize.height() != oldSize.height())-
1304 emit minimumHeightChanged(d->minimumSize.height());-
1305}-
1306-
1307/*!-
1308 \property QWindow::x-
1309 \brief the x position of the window's geometry-
1310*/-
1311void QWindow::setX(int arg)-
1312{-
1313 Q_D(QWindow);-
1314 if (x() != arg)-
1315 setGeometry(QRect(arg, y(), width(), height()));-
1316 else-
1317 d->positionAutomatic = false;-
1318}-
1319-
1320/*!-
1321 \property QWindow::y-
1322 \brief the y position of the window's geometry-
1323*/-
1324void QWindow::setY(int arg)-
1325{-
1326 Q_D(QWindow);-
1327 if (y() != arg)-
1328 setGeometry(QRect(x(), arg, width(), height()));-
1329 else-
1330 d->positionAutomatic = false;-
1331}-
1332-
1333/*!-
1334 \property QWindow::width-
1335 \brief the width of the window's geometry-
1336*/-
1337void QWindow::setWidth(int arg)-
1338{-
1339 if (width() != arg)-
1340 resize(arg, height());-
1341}-
1342-
1343/*!-
1344 \property QWindow::height-
1345 \brief the height of the window's geometry-
1346*/-
1347void QWindow::setHeight(int arg)-
1348{-
1349 if (height() != arg)-
1350 resize(width(), arg);-
1351}-
1352-
1353/*!-
1354 \property QWindow::minimumWidth-
1355 \brief the minimum width of the window's geometry-
1356*/-
1357void QWindow::setMinimumWidth(int w)-
1358{-
1359 setMinimumSize(QSize(w, minimumHeight()));-
1360}-
1361-
1362/*!-
1363 \property QWindow::minimumHeight-
1364 \brief the minimum height of the window's geometry-
1365*/-
1366void QWindow::setMinimumHeight(int h)-
1367{-
1368 setMinimumSize(QSize(minimumWidth(), h));-
1369}-
1370-
1371/*!-
1372 Sets the maximum size of the window.-
1373-
1374 This is a hint to the window manager to prevent resizing above the specified \a size.-
1375-
1376 \sa setMinimumSize(), maximumSize()-
1377*/-
1378void QWindow::setMaximumSize(const QSize &size)-
1379{-
1380 Q_D(QWindow);-
1381 QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));-
1382 if (d->maximumSize == adjustedSize)-
1383 return;-
1384 QSize oldSize = d->maximumSize;-
1385 d->maximumSize = adjustedSize;-
1386 if (d->platformWindow && isTopLevel())-
1387 d->platformWindow->propagateSizeHints();-
1388 if (d->maximumSize.width() != oldSize.width())-
1389 emit maximumWidthChanged(d->maximumSize.width());-
1390 if (d->maximumSize.height() != oldSize.height())-
1391 emit maximumHeightChanged(d->maximumSize.height());-
1392}-
1393-
1394/*!-
1395 \property QWindow::maximumWidth-
1396 \brief the maximum width of the window's geometry-
1397*/-
1398void QWindow::setMaximumWidth(int w)-
1399{-
1400 setMaximumSize(QSize(w, maximumHeight()));-
1401}-
1402-
1403/*!-
1404 \property QWindow::maximumHeight-
1405 \brief the maximum height of the window's geometry-
1406*/-
1407void QWindow::setMaximumHeight(int h)-
1408{-
1409 setMaximumSize(QSize(maximumWidth(), h));-
1410}-
1411-
1412/*!-
1413 Sets the base \a size of the window.-
1414-
1415 The base size is used to calculate a proper window size if the-
1416 window defines sizeIncrement().-
1417-
1418 \sa setMinimumSize(), setMaximumSize(), setSizeIncrement(), baseSize()-
1419*/-
1420void QWindow::setBaseSize(const QSize &size)-
1421{-
1422 Q_D(QWindow);-
1423 if (d->baseSize == size)-
1424 return;-
1425 d->baseSize = size;-
1426 if (d->platformWindow && isTopLevel())-
1427 d->platformWindow->propagateSizeHints();-
1428}-
1429-
1430/*!-
1431 Sets the size increment (\a size) of the window.-
1432-
1433 When the user resizes the window, the size will move in steps of-
1434 sizeIncrement().width() pixels horizontally and-
1435 sizeIncrement().height() pixels vertically, with baseSize() as the-
1436 basis.-
1437-
1438 By default, this property contains a size with zero width and height.-
1439-
1440 The windowing system might not support size increments.-
1441-
1442 \sa setBaseSize(), setMinimumSize(), setMaximumSize()-
1443*/-
1444void QWindow::setSizeIncrement(const QSize &size)-
1445{-
1446 Q_D(QWindow);-
1447 if (d->sizeIncrement == size)-
1448 return;-
1449 d->sizeIncrement = size;-
1450 if (d->platformWindow && isTopLevel())-
1451 d->platformWindow->propagateSizeHints();-
1452}-
1453-
1454/*!-
1455 Sets the geometry of the window, excluding its window frame, to a-
1456 rectangle constructed from \a posx, \a posy, \a w and \a h.-
1457-
1458 \sa geometry()-
1459*/-
1460void QWindow::setGeometry(int posx, int posy, int w, int h)-
1461{-
1462 setGeometry(QRect(posx, posy, w, h));-
1463}-
1464-
1465/*!-
1466 \brief Sets the geometry of the window, excluding its window frame, to \a rect.-
1467-
1468 \sa geometry()-
1469*/-
1470void QWindow::setGeometry(const QRect &rect)-
1471{-
1472 Q_D(QWindow);-
1473 d->positionAutomatic = false;-
1474 const QRect oldRect = geometry();-
1475 if (rect == geometry())oldRect)
rect == oldRectDescription
TRUEnever evaluated
FALSEnever evaluated
0
1476 return;
never executed: return;
0
1477-
1478 QRect oldRect = geometry();d->positionPolicy = QWindowPrivate::WindowFrameExclusive;-
1479 if (d->platformWindow) {
d->platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1480 QRect nativeRect;-
1481 QScreen *newScreen = d->screenForGeometry(rect);-
1482 if (newScreen && isTopLevel())
newScreenDescription
TRUEnever evaluated
FALSEnever evaluated
isTopLevel()Description
TRUEnever evaluated
FALSEnever evaluated
0
1483 nativeRect = QHighDpi::toNativePixels(rect, newScreen);
never executed: nativeRect = QHighDpi::toNativePixels(rect, newScreen);
0
1484 else-
1485 nativeRect = QHighDpi::toNativePixels(rect, this);
never executed: nativeRect = QHighDpi::toNativePixels(rect, this);
0
1486 d->platformWindow->setGeometry(nativeRect);-
1487 } else {
never executed: end of block
0
1488 d->geometry = rect;-
1489-
1490 if (rect.x() != oldRect.x())
rect.x() != oldRect.x()Description
TRUEnever evaluated
FALSEnever evaluated
0
1491 emit xChanged(rect.x());
never executed: xChanged(rect.x());
0
1492 if (rect.y() != oldRect.y())
rect.y() != oldRect.y()Description
TRUEnever evaluated
FALSEnever evaluated
0
1493 emit yChanged(rect.y());
never executed: yChanged(rect.y());
0
1494 if (rect.width() != oldRect.width())
rect.width() !...ldRect.width()Description
TRUEnever evaluated
FALSEnever evaluated
0
1495 emit widthChanged(rect.width());
never executed: widthChanged(rect.width());
0
1496 if (rect.height() != oldRect.height())
rect.height() ...dRect.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
1497 emit heightChanged(rect.height());
never executed: heightChanged(rect.height());
0
1498 }
never executed: end of block
0
1499}-
1500-
1501/*-
1502 This is equivalent to QPlatformWindow::screenForGeometry, but in platform-
1503 independent coordinates. The duplication is unfortunate, but there is a-
1504 chicken and egg problem here: we cannot convert to native coordinates-
1505 before we know which screen we are on.-
1506*/-
1507QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry)-
1508{-
1509 Q_Q(QWindow);-
1510 QScreen *currentScreen = q->screen();-
1511 QScreen *fallback = currentScreen;-
1512 QPoint center = newGeometry.center();-
1513 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
!q->parent()Description
TRUEnever evaluated
FALSEnever evaluated
currentScreenDescription
TRUEnever evaluated
FALSEnever evaluated
!currentScreen...ntains(center)Description
TRUEnever evaluated
FALSEnever evaluated
0
1514 Q_FOREACHconst auto screens = currentScreen->virtualSiblings();-
1515 for (QScreen* screen , currentScreen->virtualSiblings()): screens) {-
1516 if (screen->geometry().contains(center))
screen->geomet...ntains(center)Description
TRUEnever evaluated
FALSEnever evaluated
0
1517 return screen;
never executed: return screen;
0
1518 if (screen->geometry().intersects(newGeometry))
screen->geomet...s(newGeometry)Description
TRUEnever evaluated
FALSEnever evaluated
0
1519 fallback = screen;
never executed: fallback = screen;
0
1520 }
never executed: end of block
0
1521 }
never executed: end of block
0
1522 return fallback;
never executed: return fallback;
0
1523}-
1524-
1525-
1526/*!-
1527 Returns the geometry of the window, excluding its window frame.-
1528-
1529 \sa frameMargins(), frameGeometry()-
1530*/-
1531QRect QWindow::geometry() const-
1532{-
1533 Q_D(const QWindow);-
1534 if (d->platformWindow)-
1535 return QHighDpi::fromNativePixels(d->platformWindow->geometry(), this);-
1536 return d->geometry;-
1537}-
1538-
1539/*!-
1540 Returns the window frame margins surrounding the window.-
1541-
1542 \sa geometry(), frameGeometry()-
1543*/-
1544QMargins QWindow::frameMargins() const-
1545{-
1546 Q_D(const QWindow);-
1547 if (d->platformWindow)-
1548 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(), this);-
1549 return QMargins();-
1550}-
1551-
1552/*!-
1553 Returns the geometry of the window, including its window frame.-
1554-
1555 \sa geometry(), frameMargins()-
1556*/-
1557QRect QWindow::frameGeometry() const-
1558{-
1559 Q_D(const QWindow);-
1560 if (d->platformWindow) {-
1561 QMargins m = frameMargins();-
1562 return QHighDpi::fromNativePixels(d->platformWindow->geometry(), this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());-
1563 }-
1564 return d->geometry;-
1565}-
1566-
1567/*!-
1568 Returns the top left position of the window, including its window frame.-
1569-
1570 This returns the same value as frameGeometry().topLeft().-
1571-
1572 \sa geometry(), frameGeometry()-
1573*/-
1574QPoint QWindow::framePosition() const-
1575{-
1576 Q_D(const QWindow);-
1577 if (d->platformWindow) {-
1578 QMargins margins = frameMargins();-
1579 return QHighDpi::fromNativePixels(d->platformWindow->geometry().topLeft(), this) - QPoint(margins.left(), margins.top());-
1580 }-
1581 return d->geometry.topLeft();-
1582}-
1583-
1584/*!-
1585 Sets the upper left position of the window (\a point) including its window frame.-
1586-
1587 \sa setGeometry(), frameGeometry()-
1588*/-
1589void QWindow::setFramePosition(const QPoint &point)-
1590{-
1591 Q_D(QWindow);-
1592 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;-
1593 d->positionAutomatic = false;-
1594 if (d->platformWindow) {-
1595 d->platformWindow->setGeometry(QHighDpi::toNativePixels(QRect(point, size()), this));-
1596 } else {-
1597 d->geometry.moveTopLeft(point);-
1598 }-
1599}-
1600-
1601/*!-
1602 \brief set the position of the window on the desktop to \a pt-
1603-
1604 \sa position()-
1605*/-
1606void QWindow::setPosition(const QPoint &pt)-
1607{-
1608 setGeometry(QRect(pt, size()));-
1609}-
1610-
1611/*!-
1612 \brief set the position of the window on the desktop to \a posx, \a posy-
1613-
1614 \sa position()-
1615*/-
1616void QWindow::setPosition(int posx, int posy)-
1617{-
1618 setPosition(QPoint(posx, posy));-
1619}-
1620-
1621/*!-
1622 \fn QPoint QWindow::position() const-
1623 \brief Returns the position of the window on the desktop excluding any window frame-
1624-
1625 \sa setPosition()-
1626*/-
1627-
1628/*!-
1629 \fn QSize QWindow::size() const-
1630 \brief Returns the size of the window excluding any window frame-
1631-
1632 \sa resize()-
1633*/-
1634-
1635/*!-
1636 set the size of the window, excluding any window frame, to a QSize-
1637 constructed from width \a w and height \a h-
1638-
1639 \sa size(), geometry()-
1640*/-
1641void QWindow::resize(int w, int h)-
1642{-
1643 resize(QSize(w, h));-
1644}-
1645-
1646/*!-
1647 \brief set the size of the window, excluding any window frame, to \a newSize-
1648-
1649 \sa size(), geometry()-
1650*/-
1651void QWindow::resize(const QSize &newSize)-
1652{-
1653 Q_D(QWindow);-
1654 if (d->platformWindow) {-
1655 d->platformWindow->setGeometry(QHighDpi::toNativePixels(QRect(position(), newSize), this));-
1656 } else {-
1657 const QSize oldSize = d->geometry.size();-
1658 d->geometry.setSize(newSize);-
1659 if (newSize.width() != oldSize.width())-
1660 emit widthChanged(newSize.width());-
1661 if (newSize.height() != oldSize.height())-
1662 emit heightChanged(newSize.height());-
1663 }-
1664}-
1665-
1666/*!-
1667 Releases the native platform resources associated with this window.-
1668-
1669 \sa create()-
1670*/-
1671void QWindow::destroy()-
1672{-
1673 Q_D(QWindow);-
1674 if (!d->platformWindow)
!d->platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1675 return;
never executed: return;
0
1676-
1677 QObjectList childrenWindows = children();-
1678 for (int i = 0; i < childrenWindows.size(); i++) {
i < childrenWindows.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1679 QObject *object = childrenWindows.at(i);-
1680 if (object->isWindowType()) {
object->isWindowType()Description
TRUEnever evaluated
FALSEnever evaluated
0
1681 QWindow *w = static_cast<QWindow*>(object);-
1682 w->destroy();-
1683 }
never executed: end of block
0
1684 }
never executed: end of block
0
1685-
1686 if (QGuiApplicationPrivate::focus_window == this)
QGuiApplicatio...window == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1687 QGuiApplicationPrivate::focus_window = parent();
never executed: QGuiApplicationPrivate::focus_window = parent();
0
1688 if (QGuiApplicationPrivate::currentMouseWindow == this)
QGuiApplicatio...Window == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1689 QGuiApplicationPrivate::currentMouseWindow = parent();
never executed: QGuiApplicationPrivate::currentMouseWindow = parent();
0
1690 if (QGuiApplicationPrivate::currentMousePressWindow == this)
QGuiApplicatio...Window == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1691 QGuiApplicationPrivate::currentMousePressWindow = parent();
never executed: QGuiApplicationPrivate::currentMousePressWindow = parent();
0
1692-
1693 for (int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size
i < QGuiApplic...ePoints.size()Description
TRUEnever evaluated
FALSEnever evaluated
(); ++i)
i < QGuiApplic...ePoints.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1694 if (QGuiApplicationPrivate::tabletPressTargettabletDevicePoints.at(i).target == this)
QGuiApplicatio...target == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1695 QGuiApplicationPrivate::tabletPressTargettabletDevicePoints[i].target = parent();
never executed: QGuiApplicationPrivate::tabletDevicePoints[i].target = parent();
0
1696-
1697 bool wasVisible = isVisible();-
1698 d->visibilityOnDestroy = wasVisible && d->platformWindow;
wasVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
d->platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1699-
1700 setVisible(false);-
1701-
1702 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);-
1703 QGuiApplication::sendEvent(this, &e);-
1704-
1705 delete d->platformWindow;-
1706 d->resizeEventPending = true;-
1707 d->receivedExpose = false;-
1708 d->exposed = false;-
1709 d->platformWindow = 0;-
1710-
1711 if (wasVisible)
wasVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1712 d->maybeQuitOnLastWindowClosed();
never executed: d->maybeQuitOnLastWindowClosed();
0
1713}
never executed: end of block
0
1714-
1715/*!-
1716 Returns the platform window corresponding to the window.-
1717-
1718 \internal-
1719*/-
1720QPlatformWindow *QWindow::handle() const-
1721{-
1722 Q_D(const QWindow);-
1723 return d->platformWindow;-
1724}-
1725-
1726/*!-
1727 Returns the platform surface corresponding to the window.-
1728-
1729 \internal-
1730*/-
1731QPlatformSurface *QWindow::surfaceHandle() const-
1732{-
1733 Q_D(const QWindow);-
1734 return d->platformWindow;-
1735}-
1736-
1737/*!-
1738 Sets whether keyboard grab should be enabled or not (\a grab).-
1739-
1740 If the return value is true, the window receives all key events until-
1741 setKeyboardGrabEnabled(false) is called; other windows get no key events at-
1742 all. Mouse events are not affected. Use setMouseGrabEnabled() if you want-
1743 to grab that.-
1744-
1745 \sa setMouseGrabEnabled()-
1746*/-
1747bool QWindow::setKeyboardGrabEnabled(bool grab)-
1748{-
1749 Q_D(QWindow);-
1750 if (d->platformWindow)-
1751 return d->platformWindow->setKeyboardGrabEnabled(grab);-
1752 return false;-
1753}-
1754-
1755/*!-
1756 Sets whether mouse grab should be enabled or not (\a grab).-
1757-
1758 If the return value is true, the window receives all mouse events until setMouseGrabEnabled(false) is-
1759 called; other windows get no mouse events at all. Keyboard events are not affected.-
1760 Use setKeyboardGrabEnabled() if you want to grab that.-
1761-
1762 \sa setKeyboardGrabEnabled()-
1763*/-
1764bool QWindow::setMouseGrabEnabled(bool grab)-
1765{-
1766 Q_D(QWindow);-
1767 if (d->platformWindow)-
1768 return d->platformWindow->setMouseGrabEnabled(grab);-
1769 return false;-
1770}-
1771-
1772/*!-
1773 Returns the screen on which the window is shown, or null if there is none.-
1774-
1775 For child windows, this returns the screen of the corresponding top level window.-
1776-
1777 \sa setScreen(), QScreen::virtualSiblings()-
1778*/-
1779QScreen *QWindow::screen() const-
1780{-
1781 Q_D(const QWindow);-
1782 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();-
1783}-
1784-
1785/*!-
1786 Sets the screen on which the window should be shown.-
1787-
1788 If the window has been created, it will be recreated on the \a newScreen.-
1789-
1790 Note that if the screen is part of a virtual desktop of multiple screens,-
1791 the window can appear on any of the screens returned by QScreen::virtualSiblings().-
1792-
1793 This function only works for top level windows.-
1794-
1795 \sa screen(), QScreen::virtualSiblings()-
1796*/-
1797void QWindow::setScreen(QScreen *newScreen)-
1798{-
1799 Q_D(QWindow);-
1800 if (!newScreen)-
1801 newScreen = QGuiApplication::primaryScreen();-
1802 d->setTopLevelScreen(newScreen, newScreen != 0);-
1803}-
1804-
1805/*!-
1806 \fn QWindow::screenChanged(QScreen *screen)-
1807-
1808 This signal is emitted when a window's \a screen changes, either-
1809 by being set explicitly with setScreen(), or automatically when-
1810 the window's screen is removed.-
1811*/-
1812-
1813/*!-
1814 Returns the accessibility interface for the object that the window represents-
1815 \internal-
1816 \sa QAccessible-
1817 */-
1818QAccessibleInterface *QWindow::accessibleRoot() const-
1819{-
1820 return 0;-
1821}-
1822-
1823/*!-
1824 \fn QWindow::focusObjectChanged(QObject *object)-
1825-
1826 This signal is emitted when the final receiver of events tied to focus-
1827 is changed to \a object.-
1828-
1829 \sa focusObject()-
1830*/-
1831-
1832/*!-
1833 Returns the QObject that will be the final receiver of events tied focus, such-
1834 as key events.-
1835*/-
1836QObject *QWindow::focusObject() const-
1837{-
1838 return const_cast<QWindow *>(this);-
1839}-
1840-
1841/*!-
1842 Shows the window.-
1843-
1844 This is equivalent to calling showFullScreen(), showMaximized(), or showNormal(),-
1845 depending on the platform's default behavior for the window type and flags.-
1846-
1847 \sa showFullScreen(), showMaximized(), showNormal(), hide(), QStyleHints::showIsFullScreen(), flags()-
1848*/-
1849void QWindow::show()-
1850{-
1851 Qt::WindowState defaultState = QGuiApplicationPrivate::platformIntegration()->defaultWindowState(d_func()->windowFlags);-
1852 if (defaultState == Qt::WindowFullScreen)-
1853 showFullScreen();-
1854 else if (defaultState == Qt::WindowMaximized)-
1855 showMaximized();-
1856 else-
1857 showNormal();-
1858}-
1859-
1860/*!-
1861 Hides the window.-
1862-
1863 Equivalent to calling setVisible(false).-
1864-
1865 \sa show(), setVisible()-
1866*/-
1867void QWindow::hide()-
1868{-
1869 setVisible(false);-
1870}-
1871-
1872/*!-
1873 Shows the window as minimized.-
1874-
1875 Equivalent to calling setWindowState(Qt::WindowMinimized) and then-
1876 setVisible(true).-
1877-
1878 \sa setWindowState(), setVisible()-
1879*/-
1880void QWindow::showMinimized()-
1881{-
1882 setWindowState(Qt::WindowMinimized);-
1883 setVisible(true);-
1884}-
1885-
1886/*!-
1887 Shows the window as maximized.-
1888-
1889 Equivalent to calling setWindowState(Qt::WindowMaximized) and then-
1890 setVisible(true).-
1891-
1892 \sa setWindowState(), setVisible()-
1893*/-
1894void QWindow::showMaximized()-
1895{-
1896 setWindowState(Qt::WindowMaximized);-
1897 setVisible(true);-
1898}-
1899-
1900/*!-
1901 Shows the window as fullscreen.-
1902-
1903 Equivalent to calling setWindowState(Qt::WindowFullScreen) and then-
1904 setVisible(true).-
1905-
1906 \sa setWindowState(), setVisible()-
1907*/-
1908void QWindow::showFullScreen()-
1909{-
1910 setWindowState(Qt::WindowFullScreen);-
1911 setVisible(true);-
1912#if !defined Q_OS_QNX // On QNX this window will be activated anyway from libscreen-
1913 // activating it here before libscreen activates it causes problems-
1914 requestActivate();-
1915#endif-
1916}-
1917-
1918/*!-
1919 Shows the window as normal, i.e. neither maximized, minimized, nor fullscreen.-
1920-
1921 Equivalent to calling setWindowState(Qt::WindowNoState) and then-
1922 setVisible(true).-
1923-
1924 \sa setWindowState(), setVisible()-
1925*/-
1926void QWindow::showNormal()-
1927{-
1928 setWindowState(Qt::WindowNoState);-
1929 setVisible(true);-
1930}-
1931-
1932/*!-
1933 Close the window.-
1934-
1935 This closes the window, effectively calling destroy(), and potentially-
1936 quitting the application. Returns \c true on success, false if it has a parent-
1937 window (in which case the top level window should be closed instead).-
1938-
1939 \sa destroy(), QGuiApplication::quitOnLastWindowClosed()-
1940*/-
1941bool QWindow::close()-
1942{-
1943 Q_D(QWindow);-
1944-
1945 // Do not close non top level windows-
1946 if (parent())-
1947 return false;-
1948-
1949 if (!d->platformWindow)-
1950 return true;-
1951-
1952 bool accepted = false;-
1953 QWindowSystemInterface::handleCloseEvent(this, &accepted);-
1954 QWindowSystemInterface::flushWindowSystemEvents();-
1955 return accepted;-
1956}-
1957-
1958/*!-
1959 The expose event (\a ev) is sent by the window system whenever the window's-
1960 exposure on screen changes.-
1961-
1962 The application can start rendering into the window with QBackingStore-
1963 and QOpenGLContext as soon as it gets an exposeEvent() such that-
1964 isExposed() is true.-
1965-
1966 If the window is moved off screen, is made totally obscured by another-
1967 window, iconified or similar, this function might be called and the-
1968 value of isExposed() might change to false. When this happens,-
1969 an application should stop its rendering as it is no longer visible-
1970 to the user.-
1971-
1972 A resize event will always be sent before the expose event the first time-
1973 a window is shown.-
1974-
1975 \sa isExposed()-
1976*/-
1977void QWindow::exposeEvent(QExposeEvent *ev)-
1978{-
1979 ev->ignore();-
1980}-
1981-
1982/*!-
1983 Override this to handle window move events (\a ev).-
1984*/-
1985void QWindow::moveEvent(QMoveEvent *ev)-
1986{-
1987 ev->ignore();-
1988}-
1989-
1990/*!-
1991 Override this to handle resize events (\a ev).-
1992-
1993 The resize event is called whenever the window is resized in the windowing system,-
1994 either directly through the windowing system acknowledging a setGeometry() or resize() request,-
1995 or indirectly through the user resizing the window manually.-
1996*/-
1997void QWindow::resizeEvent(QResizeEvent *ev)-
1998{-
1999 ev->ignore();-
2000}-
2001-
2002/*!-
2003 Override this to handle show events (\a ev).-
2004-
2005 The function is called when the window has requested becoming visible.-
2006-
2007 If the window is successfully shown by the windowing system, this will-
2008 be followed by a resize and an expose event.-
2009*/-
2010void QWindow::showEvent(QShowEvent *ev)-
2011{-
2012 ev->ignore();-
2013}-
2014-
2015/*!-
2016 Override this to handle hide events (\a ev).-
2017-
2018 The function is called when the window has requested being hidden in the-
2019 windowing system.-
2020*/-
2021void QWindow::hideEvent(QHideEvent *ev)-
2022{-
2023 ev->ignore();-
2024}-
2025-
2026/*!-
2027 Override this to handle any event (\a ev) sent to the window.-
2028 Return \c true if the event was recognized and processed.-
2029-
2030 Remember to call the base class version if you wish for mouse events,-
2031 key events, resize events, etc to be dispatched as usual.-
2032*/-
2033bool QWindow::event(QEvent *ev)-
2034{-
2035 switch (ev->type()) {-
2036 case QEvent::MouseMove:-
2037 mouseMoveEvent(static_cast<QMouseEvent*>(ev));-
2038 break;-
2039-
2040 case QEvent::MouseButtonPress:-
2041 mousePressEvent(static_cast<QMouseEvent*>(ev));-
2042 break;-
2043-
2044 case QEvent::MouseButtonRelease:-
2045 mouseReleaseEvent(static_cast<QMouseEvent*>(ev));-
2046 break;-
2047-
2048 case QEvent::MouseButtonDblClick:-
2049 mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));-
2050 break;-
2051-
2052 case QEvent::TouchBegin:-
2053 case QEvent::TouchUpdate:-
2054 case QEvent::TouchEnd:-
2055 case QEvent::TouchCancel:-
2056 touchEvent(static_cast<QTouchEvent *>(ev));-
2057 break;-
2058-
2059 case QEvent::Move:-
2060 moveEvent(static_cast<QMoveEvent*>(ev));-
2061 break;-
2062-
2063 case QEvent::Resize:-
2064 resizeEvent(static_cast<QResizeEvent*>(ev));-
2065 break;-
2066-
2067 case QEvent::KeyPress:-
2068 keyPressEvent(static_cast<QKeyEvent *>(ev));-
2069 break;-
2070-
2071 case QEvent::KeyRelease:-
2072 keyReleaseEvent(static_cast<QKeyEvent *>(ev));-
2073 break;-
2074-
2075 case QEvent::FocusIn: {-
2076 focusInEvent(static_cast<QFocusEvent *>(ev));-
2077#ifndef QT_NO_ACCESSIBILITY-
2078 QAccessible::State state;-
2079 state.active = true;-
2080 QAccessibleStateChangeEvent event(this, state);-
2081 QAccessible::updateAccessibility(&event);-
2082#endif-
2083 break; }-
2084-
2085 case QEvent::FocusOut: {-
2086 focusOutEvent(static_cast<QFocusEvent *>(ev));-
2087#ifndef QT_NO_ACCESSIBILITY-
2088 QAccessible::State state;-
2089 state.active = true;-
2090 QAccessibleStateChangeEvent event(this, state);-
2091 QAccessible::updateAccessibility(&event);-
2092#endif-
2093 break; }-
2094-
2095#ifndef QT_NO_WHEELEVENT-
2096 case QEvent::Wheel:-
2097 wheelEvent(static_cast<QWheelEvent*>(ev));-
2098 break;-
2099#endif-
2100-
2101 case QEvent::Close:-
2102 if (ev->isAccepted())-
2103 destroy();-
2104 break;-
2105-
2106 case QEvent::Expose:-
2107 exposeEvent(static_cast<QExposeEvent *>(ev));-
2108 break;-
2109-
2110 case QEvent::Show:-
2111 showEvent(static_cast<QShowEvent *>(ev));-
2112 break;-
2113-
2114 case QEvent::Hide:-
2115 hideEvent(static_cast<QHideEvent *>(ev));-
2116 break;-
2117-
2118 case QEvent::ApplicationWindowIconChange:-
2119 setIcon(icon());-
2120 break;-
2121-
2122 case QEvent::WindowStateChange: {-
2123 Q_D(QWindow);-
2124 emit windowStateChanged(d->windowState);-
2125 d->updateVisibility();-
2126 break;-
2127 }-
2128-
2129#ifndef QT_NO_TABLETEVENT-
2130 case QEvent::TabletPress:-
2131 case QEvent::TabletMove:-
2132 case QEvent::TabletRelease:-
2133 tabletEvent(static_cast<QTabletEvent *>(ev));-
2134 break;-
2135#endif-
2136-
2137 case QEvent::Timer: {-
2138 Q_D(QWindow);-
2139 if (static_cast<QTimerEvent *>(ev)->timerId() == d->updateTimer) {-
2140 killTimer(d->updateTimer);-
2141 d->updateTimer = 0;-
2142 d->deliverUpdateRequest();-
2143 } else {-
2144 QObject::event(ev);-
2145 }-
2146 break;-
2147 }-
2148-
2149 case QEvent::PlatformSurface: {-
2150 if ((static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {-
2151#ifndef QT_NO_OPENGL-
2152 QOpenGLContext *context = QOpenGLContext::currentContext();-
2153 if (context && context->surface() == static_cast<QSurface *>(this))-
2154 context->doneCurrent();-
2155#endif-
2156 }-
2157 break;-
2158 }-
2159-
2160 default:-
2161 return QObject::event(ev);-
2162 }-
2163 return true;-
2164}-
2165-
2166void QWindowPrivate::deliverUpdateRequest()-
2167{-
2168 Q_Q(QWindow);-
2169 updateRequestPending = false;-
2170 QEvent request(QEvent::UpdateRequest);-
2171 QCoreApplication::sendEvent(q, &request);-
2172}-
2173-
2174/*!-
2175 Schedules a QEvent::UpdateRequest event to be delivered to this window.-
2176-
2177 The event is delivered in sync with the display vsync on platforms-
2178 where this is possible. When driving animations, this function should-
2179 be called once after drawing has completed.-
2180-
2181 Calling this function multiple times will result in a single event-
2182 being delivered to the window.-
2183-
2184 Subclasses of QWindow should reimplement event(), intercept the event and-
2185 call the application's rendering code, then call the base class-
2186 implementation.-
2187-
2188 \note The subclass' reimplementation of event() must invoke the base class-
2189 implementation, unless it is absolutely sure that the event does not need to-
2190 be handled by the base class. For example, the default implementation of-
2191 this function relies on QEvent::Timer events. Filtering them away would-
2192 therefore break the delivery of the update events.-
2193-
2194 \since 5.5-
2195*/-
2196void QWindow::requestUpdate()-
2197{-
2198 Q_ASSERT_X(QThread::currentThread() == QCoreApplication::instance()->thread(),-
2199 "QWindow", "Updates can only be scheduled from the GUI (main) thread");-
2200-
2201 Q_D(QWindow);-
2202 if (d->updateRequestPending || !d->platformWindow)-
2203 return;-
2204 d->updateRequestPending = true;-
2205 d->platformWindow->requestUpdate();-
2206}-
2207-
2208/*!-
2209 Override this to handle key press events (\a ev).-
2210-
2211 \sa keyReleaseEvent()-
2212*/-
2213void QWindow::keyPressEvent(QKeyEvent *ev)-
2214{-
2215 ev->ignore();-
2216}-
2217-
2218/*!-
2219 Override this to handle key release events (\a ev).-
2220-
2221 \sa keyPressEvent()-
2222*/-
2223void QWindow::keyReleaseEvent(QKeyEvent *ev)-
2224{-
2225 ev->ignore();-
2226}-
2227-
2228/*!-
2229 Override this to handle focus in events (\a ev).-
2230-
2231 Focus in events are sent when the window receives keyboard focus.-
2232-
2233 \sa focusOutEvent()-
2234*/-
2235void QWindow::focusInEvent(QFocusEvent *ev)-
2236{-
2237 ev->ignore();-
2238}-
2239-
2240/*!-
2241 Override this to handle focus out events (\a ev).-
2242-
2243 Focus out events are sent when the window loses keyboard focus.-
2244-
2245 \sa focusInEvent()-
2246*/-
2247void QWindow::focusOutEvent(QFocusEvent *ev)-
2248{-
2249 ev->ignore();-
2250}-
2251-
2252/*!-
2253 Override this to handle mouse press events (\a ev).-
2254-
2255 \sa mouseReleaseEvent()-
2256*/-
2257void QWindow::mousePressEvent(QMouseEvent *ev)-
2258{-
2259 ev->ignore();-
2260}-
2261-
2262/*!-
2263 Override this to handle mouse release events (\a ev).-
2264-
2265 \sa mousePressEvent()-
2266*/-
2267void QWindow::mouseReleaseEvent(QMouseEvent *ev)-
2268{-
2269 ev->ignore();-
2270}-
2271-
2272/*!-
2273 Override this to handle mouse double click events (\a ev).-
2274-
2275 \sa mousePressEvent(), QStyleHints::mouseDoubleClickInterval()-
2276*/-
2277void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)-
2278{-
2279 ev->ignore();-
2280}-
2281-
2282/*!-
2283 Override this to handle mouse move events (\a ev).-
2284*/-
2285void QWindow::mouseMoveEvent(QMouseEvent *ev)-
2286{-
2287 ev->ignore();-
2288}-
2289-
2290#ifndef QT_NO_WHEELEVENT-
2291/*!-
2292 Override this to handle mouse wheel or other wheel events (\a ev).-
2293*/-
2294void QWindow::wheelEvent(QWheelEvent *ev)-
2295{-
2296 ev->ignore();-
2297}-
2298#endif //QT_NO_WHEELEVENT-
2299-
2300/*!-
2301 Override this to handle touch events (\a ev).-
2302*/-
2303void QWindow::touchEvent(QTouchEvent *ev)-
2304{-
2305 ev->ignore();-
2306}-
2307-
2308#ifndef QT_NO_TABLETEVENT-
2309/*!-
2310 Override this to handle tablet press, move, and release events (\a ev).-
2311-
2312 Proximity enter and leave events are not sent to windows, they are-
2313 delivered to the application instance.-
2314*/-
2315void QWindow::tabletEvent(QTabletEvent *ev)-
2316{-
2317 ev->ignore();-
2318}-
2319#endif-
2320-
2321/*!-
2322 Override this to handle platform dependent events.-
2323 Will be given \a eventType, \a message and \a result.-
2324-
2325 This might make your application non-portable.-
2326-
2327 Should return true only if the event was handled.-
2328*/-
2329bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)-
2330{-
2331 Q_UNUSED(eventType);-
2332 Q_UNUSED(message);-
2333 Q_UNUSED(result);-
2334 return false;-
2335}-
2336-
2337/*!-
2338 \fn QPoint QWindow::mapToGlobal(const QPoint &pos) const-
2339-
2340 Translates the window coordinate \a pos to global screen-
2341 coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give-
2342 the global coordinates of the top-left pixel of the window.-
2343-
2344 \sa mapFromGlobal()-
2345*/-
2346QPoint QWindow::mapToGlobal(const QPoint &pos) const-
2347{-
2348 Q_D(const QWindow);-
2349 // QTBUG-43252, prefer platform implementation for foreign windows.-
2350 if (d->platformWindow-
2351 && (type() == Qt::ForeignWindow || d->platformWindow->isEmbedded())) {-
2352 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapToGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this);-
2353 }-
2354 return pos + d->globalPosition();-
2355}-
2356-
2357-
2358/*!-
2359 \fn QPoint QWindow::mapFromGlobal(const QPoint &pos) const-
2360-
2361 Translates the global screen coordinate \a pos to window-
2362 coordinates.-
2363-
2364 \sa mapToGlobal()-
2365*/-
2366QPoint QWindow::mapFromGlobal(const QPoint &pos) const-
2367{-
2368 Q_D(const QWindow);-
2369 // QTBUG-43252, prefer platform implementation for foreign windows.-
2370 if (d->platformWindow-
2371 && (type() == Qt::ForeignWindow || d->platformWindow->isEmbedded())) {-
2372 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this);-
2373 }-
2374 return pos - d->globalPosition();-
2375}-
2376-
2377-
2378Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window)-
2379{-
2380 return window->d_func();-
2381}-
2382-
2383void QWindowPrivate::maybeQuitOnLastWindowClosed()-
2384{-
2385 if (!QCoreApplication::instance())-
2386 return;-
2387-
2388 Q_Q(QWindow);-
2389 // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent-
2390 bool quitOnClose = QGuiApplication::quitOnLastWindowClosed() && !q->parent();-
2391 QWindowList list = QGuiApplication::topLevelWindows();-
2392 bool lastWindowClosed = true;-
2393 for (int i = 0; i < list.size(); ++i) {-
2394 QWindow *w = list.at(i);-
2395 if (!w->isVisible() || w->transientParent() || w->type() == Qt::ToolTip)-
2396 continue;-
2397 lastWindowClosed = false;-
2398 break;-
2399 }-
2400 if (lastWindowClosed) {-
2401 QGuiApplicationPrivate::emitLastWindowClosed();-
2402 if (quitOnClose) {-
2403 QCoreApplicationPrivate *applicationPrivate = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance()));-
2404 applicationPrivate->maybeQuit();-
2405 }-
2406 }-
2407}-
2408-
2409QWindow *QWindowPrivate::topLevelWindow() const-
2410{-
2411 Q_Q(const QWindow);-
2412-
2413 QWindow *window = const_cast<QWindow *>(q);-
2414-
2415 while (window) {-
2416 QWindow *parent = window->parent();-
2417 if (!parent)-
2418 parent = window->transientParent();-
2419-
2420 if (!parent)-
2421 break;-
2422-
2423 window = parent;-
2424 }-
2425-
2426 return window;-
2427}-
2428-
2429/*!-
2430 Creates a local representation of a window created by another process or by-
2431 using native libraries below Qt.-
2432-
2433 Given the handle \a id to a native window, this method creates a QWindow-
2434 object which can be used to represent the window when invoking methods like-
2435 setParent() and setTransientParent().-
2436-
2437 This can be used, on platforms which support it, to embed a QWindow inside a-
2438 native window, or to embed a native window inside a QWindow.-
2439-
2440 If foreign windows are not supported or embedding the native window-
2441 failed in the platform plugin, this function returns 0.-
2442-
2443 \note The resulting QWindow should not be used to manipulate the underlying-
2444 native window (besides re-parenting), or to observe state changes of the-
2445 native window. Any support for these kind of operations is incidental, highly-
2446 platform dependent and untested.-
2447-
2448 \sa setParent()-
2449 \sa setTransientParent()-
2450*/-
2451QWindow *QWindow::fromWinId(WId id)-
2452{-
2453 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
!QGuiApplicati...oreignWindows)Description
TRUEnever evaluated
FALSEnever evaluated
0
2454 qWarning() << ("QWindow::fromWinId(): platform plugin does not support foreign windows.";);-
2455 return 0;
never executed: return 0;
0
2456 }-
2457-
2458 QWindow *window = new QWindow;-
2459 window->setFlags(Qt::ForeignWindow);-
2460 window->setProperty("_q_foreignWinId", QVariant::fromValue(id));-
2461 window->create();-
2462 if (!window->handle()) {
!window->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
2463 delete window;-
2464 return nullptr;
never executed: return nullptr;
0
2465 }-
2466 return window;
never executed: return window;
0
2467}-
2468-
2469/*!-
2470 Causes an alert to be shown for \a msec miliseconds. If \a msec is \c 0 (the-
2471 default), then the alert is shown indefinitely until the window becomes-
2472 active again. This function has no effect on an active window.-
2473-
2474 In alert state, the window indicates that it demands attention, for example by-
2475 flashing or bouncing the taskbar entry.-
2476-
2477 \since 5.1-
2478*/-
2479-
2480void QWindow::alert(int msec)-
2481{-
2482 Q_D(QWindow);-
2483 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())-
2484 return;-
2485 d->platformWindow->setAlertState(true);-
2486 if (d->platformWindow->isAlertState() && msec)-
2487 QTimer::singleShot(msec, this, SLOT(_q_clearAlert()));-
2488}-
2489-
2490void QWindowPrivate::_q_clearAlert()-
2491{-
2492 if (platformWindow && platformWindow->isAlertState())-
2493 platformWindow->setAlertState(false);-
2494}-
2495-
2496#ifndef QT_NO_CURSOR-
2497/*!-
2498 \brief set the cursor shape for this window-
2499-
2500 The mouse \a cursor will assume this shape when it is over this-
2501 window, unless an override cursor is set.-
2502 See the \l{Qt::CursorShape}{list of predefined cursor objects} for a-
2503 range of useful shapes.-
2504-
2505 If no cursor has been set, or after a call to unsetCursor(), the-
2506 parent window's cursor is used.-
2507-
2508 By default, the cursor has the Qt::ArrowCursor shape.-
2509-
2510 Some underlying window implementations will reset the cursor if it-
2511 leaves a window even if the mouse is grabbed. If you want to have-
2512 a cursor set for all windows, even when outside the window, consider-
2513 QGuiApplication::setOverrideCursor().-
2514-
2515 \sa QGuiApplication::setOverrideCursor()-
2516*/-
2517void QWindow::setCursor(const QCursor &cursor)-
2518{-
2519 Q_D(QWindow);-
2520 d->setCursor(&cursor);-
2521}-
2522-
2523/*!-
2524 \brief Restores the default arrow cursor for this window.-
2525 */-
2526void QWindow::unsetCursor()-
2527{-
2528 Q_D(QWindow);-
2529 d->setCursor(0);-
2530}-
2531-
2532/*!-
2533 \brief the cursor shape for this window-
2534-
2535 \sa setCursor(), unsetCursor()-
2536*/-
2537QCursor QWindow::cursor() const-
2538{-
2539 Q_D(const QWindow);-
2540 return d->cursor;-
2541}-
2542-
2543void QWindowPrivate::setCursor(const QCursor *newCursor)-
2544{-
2545-
2546 Q_Q(QWindow);-
2547 if (newCursor) {
newCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
2548 const Qt::CursorShape newShape = newCursor->shape();-
2549 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
newShape <= Qt::LastCursorDescription
TRUEnever evaluated
FALSEnever evaluated
hasCursorDescription
TRUEnever evaluated
FALSEnever evaluated
newShape == cursor.shape()Description
TRUEnever evaluated
FALSEnever evaluated
0
2550 return; // Unchanged and no bitmap/custom cursor.
never executed: return;
0
2551 cursor = *newCursor;-
2552 hasCursor = true;-
2553 } else {
never executed: end of block
0
2554 if (!hasCursor)
!hasCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
2555 return;
never executed: return;
0
2556 cursor = QCursor(Qt::ArrowCursor);-
2557 hasCursor = false;-
2558 }
never executed: end of block
0
2559 // Only attempt to set cursor and emit signal if there is an actual platform cursor-
2560 QScreen* screen = q->screen();-
2561 if (applyCursorscreen && screen->handle()->cursor()) {
screenDescription
TRUEnever evaluated
FALSEnever evaluated
screen->handle()->cursor()Description
TRUEnever evaluated
FALSEnever evaluated
0
2562 applyCursor();-
2563 QEvent event(QEvent::CursorChange);-
2564 QGuiApplication::sendEvent(q, &event);-
2565 }
never executed: end of block
0
2566}
never executed: end of block
0
2567-
boolvoid QWindowPrivate::applyCursor()
2569{-
2570 Q_Q(QWindow);-
2571 if (QScreen *screen = q->screen())platformWindow) {
platformWindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
2572 if (QPlatformCursor *platformCursor = screenq->screen()->handle()->cursor()) {
QPlatformCurso...le()->cursor()Description
TRUEnever evaluated
FALSEnever evaluated
0
2573 if (!platformWindow)-
return true;QCursor *c = QGuiApplication::overrideCursor();
2574 if (!c && hasCursor)
!cDescription
TRUEnever evaluated
FALSEnever evaluated
hasCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
2575 c = &cursor;
never executed: c = &cursor;
0
2576 platformCursor->changeCursor(c, q);-
2577 return true;}
never executed: end of block
0
2578 }return false;
never executed: end of block
0
2579}
never executed: end of block
0
2580#endif // QT_NO_CURSOR-
2581-
2582#ifndef QT_NO_DEBUG_STREAM-
2583QDebug operator<<(QDebug debug, const QWindow *window)-
2584{-
2585 QDebugStateSaver saver(debug);-
2586 debug.nospace();-
2587 if (window) {-
2588 debug << window->metaObject()->className() << '(' << (const void *)window;-
2589 if (!window->objectName().isEmpty())-
2590 debug << ", name=" << window->objectName();-
2591 if (debug.verbosity() > 2) {-
2592 const QRect geometry = window->geometry();-
2593 if (window->isVisible())-
2594 debug << ", visible";-
2595 if (window->isExposed())-
2596 debug << ", exposed";-
2597 debug << ", state=" << window->windowState()-
2598 << ", type=" << window->type() << ", flags=" << window->flags()-
2599 << ", surface type=" << window->surfaceType();-
2600 if (window->isTopLevel())-
2601 debug << ", toplevel";-
2602 debug << ", " << geometry.width() << 'x' << geometry.height()-
2603 << forcesign << geometry.x() << geometry.y() << noforcesign;-
2604 const QMargins margins = window->frameMargins();-
2605 if (!margins.isNull())-
2606 debug << ", margins=" << margins;-
2607 debug << ", devicePixelRatio=" << window->devicePixelRatio();-
2608 if (const QPlatformWindow *platformWindow = window->handle())-
2609 debug << ", winId=0x" << hex << platformWindow->winId() << dec;-
2610 if (const QScreen *screen = window->screen())-
2611 debug << ", on " << screen->name();-
2612 }-
2613 debug << ')';-
2614 } else {-
2615 debug << "QWindow(0x0)";-
2616 }-
2617 return debug;-
2618}-
2619#endif // !QT_NO_DEBUG_STREAM-
2620-
2621QT_END_NAMESPACE-
2622-
2623#include "moc_qwindow.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9