kernel/qplatformwindow.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 "qplatformwindow.h" -
43#include "qplatformwindow_p.h" -
44 -
45#include <private/qguiapplication_p.h> -
46#include <qpa/qwindowsysteminterface.h> -
47#include <QtGui/qwindow.h> -
48#include <QtGui/qscreen.h> -
49 -
50QT_BEGIN_NAMESPACE -
51 -
52/*! -
53 Constructs a platform window with the given top level window. -
54*/ -
55 -
56QPlatformWindow::QPlatformWindow(QWindow *window) -
57 : QPlatformSurface(window) -
58 , d_ptr(new QPlatformWindowPrivate) -
59{ -
60 Q_D(QPlatformWindow); -
61 d->rect = window->geometry(); -
62} -
63 -
64/*! -
65 Virtual destructor does not delete its top level window. -
66*/ -
67QPlatformWindow::~QPlatformWindow() -
68{ -
69} -
70 -
71/*! -
72 Returns the window which belongs to the QPlatformWindow -
73*/ -
74QWindow *QPlatformWindow::window() const -
75{ -
76 return static_cast<QWindow *>(m_surface); -
77} -
78 -
79/*! -
80 Returns the parent platform window (or 0 if orphan). -
81*/ -
82QPlatformWindow *QPlatformWindow::parent() const -
83{ -
84 return window()->parent() ? window()->parent()->handle() : 0; -
85} -
86 -
87/*! -
88 Returns the platform screen handle corresponding to this platform window. -
89*/ -
90QPlatformScreen *QPlatformWindow::screen() const -
91{ -
92 return window()->screen()->handle(); -
93} -
94 -
95/*! -
96 Returns the actual surface format of the window. -
97*/ -
98QSurfaceFormat QPlatformWindow::format() const -
99{ -
100 return QSurfaceFormat(); -
101} -
102 -
103/*! -
104 This function is called by Qt whenever a window is moved or the window is resized. The resize -
105 can happen programatically(from ie. user application) or by the window manager. This means that -
106 there is no need to call this function specifically from the window manager callback, instead -
107 call QWindowSystemInterface::handleGeometryChange(QWindow *w, const QRect &newRect); -
108 -
109 The position(x, y) part of the rect might be inclusive or exclusive of the window frame -
110 as returned by frameMargins(). You can detect this in the plugin by checking -
111 qt_window_private(window())->positionPolicy. -
112*/ -
113void QPlatformWindow::setGeometry(const QRect &rect) -
114{ -
115 Q_D(QPlatformWindow); -
116 d->rect = rect; -
117} -
118 -
119/*! -
120 Returnes the current geometry of a window -
121*/ -
122QRect QPlatformWindow::geometry() const -
123{ -
124 Q_D(const QPlatformWindow); -
125 return d->rect; -
126} -
127 -
128QMargins QPlatformWindow::frameMargins() const -
129{ -
130 return QMargins(); -
131} -
132 -
133/*! -
134 Reimplemented in subclasses to show the surface -
135 if \a visible is \c true, and hide it if \a visible is \c false. -
136 -
137 The default implementation sends a synchronous expose event. -
138*/ -
139void QPlatformWindow::setVisible(bool visible) -
140{ -
141 Q_UNUSED(visible); -
142 QRect rect(QPoint(), geometry().size()); -
143 QWindowSystemInterface::handleExposeEvent(window(), rect); -
144 QWindowSystemInterface::flushWindowSystemEvents(); -
145} -
146 -
147/*! -
148 Requests setting the window flags of this surface -
149 to \a flags. -
150*/ -
151void QPlatformWindow::setWindowFlags(Qt::WindowFlags flags) -
152{ -
153 Q_UNUSED(flags); -
154} -
155 -
156/*! -
157 Returns if this window is exposed in the windowing system. -
158 -
159 An exposeEvent() is sent every time this value changes. -
160 */ -
161 -
162bool QPlatformWindow::isExposed() const -
163{ -
164 return window()->isVisible(); -
165} -
166 -
167/*! -
168 Returns true if the window should appear active from a style perspective. -
169 -
170 This function can make platform-specific isActive checks, such as checking -
171 if the QWindow is embedded in an active native window. -
172*/ -
173bool QPlatformWindow::isActive() const -
174{ -
175 return false; -
176} -
177 -
178/*! -
179 Returns true if the window is a descendant of an embedded non-Qt window. -
180 Example of an embedded non-Qt window is the parent window of an in-process QAxServer. -
181 -
182 If \a parentWindow is nonzero, only check if the window is embedded in the -
183 specified \a parentWindow. -
184*/ -
185bool QPlatformWindow::isEmbedded(const QPlatformWindow *parentWindow) const -
186{ -
187 Q_UNUSED(parentWindow); -
188 return false; -
189} -
190 -
191/*! -
192 Translates the window coordinate \a pos to global screen -
193 coordinates using native methods. This is required for embedded windows, -
194 where the topmost QWindow coordinates are not global screen coordinates. -
195 -
196 Returns \a pos if there is no platform specific implementation. -
197*/ -
198QPoint QPlatformWindow::mapToGlobal(const QPoint &pos) const -
199{ -
200 return pos; -
201} -
202 -
203/*! -
204 Translates the global screen coordinate \a pos to window -
205 coordinates using native methods. This is required for embedded windows, -
206 where the topmost QWindow coordinates are not global screen coordinates. -
207 -
208 Returns \a pos if there is no platform specific implementation. -
209*/ -
210QPoint QPlatformWindow::mapFromGlobal(const QPoint &pos) const -
211{ -
212 return pos; -
213} -
214 -
215/*! -
216 Requests setting the window state of this surface -
217 to \a type. -
218 -
219 Qt::WindowActive can be ignored. -
220*/ -
221void QPlatformWindow::setWindowState(Qt::WindowState) -
222{ -
223} -
224 -
225/*! -
226 Reimplement in subclasses to return a handle to the native window -
227*/ -
228WId QPlatformWindow::winId() const -
229{ -
230 // Return anything but 0. Returning 0 would cause havoc with QWidgets on -
231 // very basic platform plugins that do not reimplement this function, -
232 // because the top-level widget's internalWinId() would always be 0 which -
233 // would mean top-levels are never treated as native. -
234 return WId(1); -
235} -
236 -
237/*! -
238 This function is called to enable native child window in QPA. It is common not to support this -
239 feature in Window systems, but can be faked. When this function is called all geometry of this -
240 platform window will be relative to the parent. -
241*/ -
242//jl: It would be useful to have a property on the platform window which indicated if the sub-class -
243// supported the setParent. If not, then geometry would be in screen coordinates. -
244void QPlatformWindow::setParent(const QPlatformWindow *parent) -
245{ -
246 Q_UNUSED(parent); -
247 qWarning("This plugin does not support setParent!"); -
248} -
249 -
250/*! -
251 Reimplement to set the window title to \a title. -
252 -
253 The implementation might want to append the application display name to -
254 the window title, like Windows and Linux do. -
255 -
256 \sa QGuiApplication::applicationDisplayName() -
257*/ -
258void QPlatformWindow::setWindowTitle(const QString &title) { Q_UNUSED(title); } -
259 -
260/*! -
261 Reimplement to set the window file path to \a filePath -
262*/ -
263void QPlatformWindow::setWindowFilePath(const QString &filePath) { Q_UNUSED(filePath); } -
264 -
265/*! -
266 Reimplement to set the window icon to \a icon -
267*/ -
268void QPlatformWindow::setWindowIcon(const QIcon &icon) { Q_UNUSED(icon); } -
269 -
270/*! -
271 Reimplement to be able to let Qt raise windows to the top of the desktop -
272*/ -
273void QPlatformWindow::raise() { qWarning("This plugin does not support raise()"); } -
274 -
275/*! -
276 Reimplement to be able to let Qt lower windows to the bottom of the desktop -
277*/ -
278void QPlatformWindow::lower() { qWarning("This plugin does not support lower()"); } -
279 -
280/*! -
281 Reimplement to propagate the size hints of the QWindow. -
282 -
283 The size hints include QWindow::minimumSize(), QWindow::maximumSize(), -
284 QWindow::sizeIncrement(), and QWindow::baseSize(). -
285*/ -
286void QPlatformWindow::propagateSizeHints() {qWarning("This plugin does not support propagateSizeHints()"); } -
287 -
288/*! -
289 Reimplement to be able to let Qt set the opacity level of a window -
290*/ -
291void QPlatformWindow::setOpacity(qreal level) -
292{ -
293 Q_UNUSED(level); -
294 qWarning("This plugin does not support setting window opacity"); -
295} -
296 -
297/*! -
298 Reimplement to be able to let Qt set the mask of a window -
299*/ -
300 -
301void QPlatformWindow::setMask(const QRegion &region) -
302{ -
303 Q_UNUSED(region); -
304 qWarning("This plugin does not support setting window masks"); -
305} -
306 -
307/*! -
308 Reimplement to let Qt be able to request activation/focus for a window -
309 -
310 Some window systems will probably not have callbacks for this functionality, -
311 and then calling QWindowSystemInterface::handleWindowActivated(QWindow *w) -
312 would be sufficient. -
313 -
314 If the window system has some event handling/callbacks then call -
315 QWindowSystemInterface::handleWindowActivated(QWindow *w) when the window system -
316 gives the notification. -
317 -
318 Default implementation calls QWindowSystem::handleWindowActivated(QWindow *w) -
319*/ -
320void QPlatformWindow::requestActivateWindow() -
321{ -
322 QWindowSystemInterface::handleWindowActivated(window()); -
323} -
324 -
325/*! -
326 Handle changes to the orientation of the platform window's contents. -
327 -
328 This is a hint to the window manager in case it needs to display -
329 additional content like popups, dialogs, status bars, or similar -
330 in relation to the window. -
331 -
332 \sa QWindow::reportContentOrientationChange() -
333*/ -
334void QPlatformWindow::handleContentOrientationChange(Qt::ScreenOrientation orientation) -
335{ -
336 Q_UNUSED(orientation); -
337} -
338 -
339/*! -
340 Reimplement this function in subclass to return the device pixel ratio -
341 for the window. This is the ratio between physical pixels -
342 and device-independent pixels. -
343 -
344 \sa QPlatformWindow::devicePixelRatio(); -
345*/ -
346qreal QPlatformWindow::devicePixelRatio() const -
347{ -
348 return 1.0; -
349} -
350 -
351bool QPlatformWindow::setKeyboardGrabEnabled(bool grab) -
352{ -
353 Q_UNUSED(grab); -
354 qWarning("This plugin does not support grabbing the keyboard"); -
355 return false; -
356} -
357 -
358bool QPlatformWindow::setMouseGrabEnabled(bool grab) -
359{ -
360 Q_UNUSED(grab); -
361 qWarning("This plugin does not support grabbing the mouse"); -
362 return false; -
363} -
364 -
365/*! -
366 Reimplement to be able to let Qt indicate that the window has been -
367 modified. Return true if the native window supports setting the modified -
368 flag, false otherwise. -
369*/ -
370bool QPlatformWindow::setWindowModified(bool modified) -
371{ -
372 Q_UNUSED(modified); -
373 return false; -
374} -
375 -
376/*! -
377 Reimplement this method to be able to do any platform specific event -
378 handling. All events for window() are passed to this function before being -
379 sent to QWindow::event(). -
380 -
381 The default implementation is empty and does nothing with \a event. -
382*/ -
383void QPlatformWindow::windowEvent(QEvent *event) -
384{ -
385 Q_UNUSED(event); -
386} -
387 -
388/*! -
389 Reimplement this method to start a system size grip drag -
390 operation if the system supports it and return true to indicate -
391 success. -
392 It is called from the mouse press event handler of the size grip. -
393 -
394 The default implementation is empty and does nothing with \a pos -
395 and \a corner. -
396*/ -
397 -
398bool QPlatformWindow::startSystemResize(const QPoint &pos, Qt::Corner corner) -
399{ -
400 Q_UNUSED(pos) -
401 Q_UNUSED(corner) -
402 return false; -
403} -
404 -
405/*! -
406 Reimplement this method to set whether frame strut events -
407 should be sent to \a enabled. -
408 -
409 \sa frameStrutEventsEnabled -
410*/ -
411 -
412void QPlatformWindow::setFrameStrutEventsEnabled(bool enabled) -
413{ -
414 if (enabled) -
415 qWarning("This plugin does not support frame strut events."); -
416} -
417 -
418/*! -
419 Reimplement this method to return whether -
420 frame strut events are enabled. -
421*/ -
422 -
423bool QPlatformWindow::frameStrutEventsEnabled() const -
424{ -
425 return false; -
426} -
427 -
428/*! -
429 Call this method to put together a window title composed of -
430 \a title -
431 \a separator -
432 the application display name -
433 -
434 If the display name isn't set, and the title is empty, the raw app name is used. -
435*/ -
436QString QPlatformWindow::formatWindowTitle(const QString &title, const QString &separator) -
437{ -
438 QString fullTitle = title;
executed (the execution status of this line is deduced): QString fullTitle = title;
-
439 if (QGuiApplicationPrivate::displayName) {
partially evaluated: QGuiApplicationPrivate::displayName
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5581
0-5581
440 // Append display name, if set. -
441 if (!fullTitle.isEmpty())
never evaluated: !fullTitle.isEmpty()
0
442 fullTitle += separator;
never executed: fullTitle += separator;
0
443 fullTitle += *QGuiApplicationPrivate::displayName;
never executed (the execution status of this line is deduced): fullTitle += *QGuiApplicationPrivate::displayName;
-
444 } else if (fullTitle.isEmpty()) {
never executed: }
evaluated: fullTitle.isEmpty()
TRUEFALSE
yes
Evaluation Count:5232
yes
Evaluation Count:349
0-5232
445 // Don't let the window title be completely empty, use the app name as fallback. -
446 fullTitle = QCoreApplication::applicationName();
executed (the execution status of this line is deduced): fullTitle = QCoreApplication::applicationName();
-
447 }
executed: }
Execution Count:5232
5232
448 return fullTitle;
executed: return fullTitle;
Execution Count:5581
5581
449} -
450 -
451/*! -
452 \class QPlatformWindow -
453 \since 4.8 -
454 \internal -
455 \preliminary -
456 \ingroup qpa -
457 -
458 \brief The QPlatformWindow class provides an abstraction for top-level windows. -
459 -
460 The QPlatformWindow abstraction is used by QWindow for all its top level windows. It is being -
461 created by calling the createPlatformWindow function in the loaded QPlatformIntegration -
462 instance. -
463 -
464 QPlatformWindow is used to signal to the windowing system, how Qt perceives its frame. -
465 However, it is not concerned with how Qt renders into the window it represents. -
466 -
467 Visible QWindows will always have a QPlatformWindow. However, it is not necessary for -
468 all windows to have a QBackingStore. This is the case for QOpenGLWidget. And could be the case for -
469 windows where some 3.party renders into it. -
470 -
471 The platform specific window handle can be retrieved by the winId function. -
472 -
473 QPlatformWindow is also the way QPA defines how native child windows should be supported -
474 through the setParent function. -
475 -
476 \section1 Implementation Aspects -
477 -
478 \list 1 -
479 \li Mouse grab: Qt expects windows to automatically grab the mouse if the user presses -
480 a button until the button is released. -
481 Automatic grab should be released if some window is explicitly grabbed. -
482 \li Enter/Leave events: If there is a window explicitly grabbing mouse events -
483 (\c{setMouseGrabEnabled()}), enter and leave events should only be sent to the -
484 grabbing window when mouse cursor passes over the grabbing window boundary. -
485 Other windows will not receive enter or leave events while the grab is active. -
486 While an automatic mouse grab caused by a mouse button press is active, no window -
487 will receive enter or leave events. When the last mouse button is released, the -
488 autograbbing window will receive leave event if mouse cursor is no longer within -
489 the window boundary. -
490 When any grab starts, the window under cursor will receive a leave event unless -
491 it is the grabbing window. -
492 When any grab ends, the window under cursor will receive an enter event unless it -
493 was the grabbing window. -
494 \li Window positioning: When calling \c{QWindow::setFramePosition()}, the flag -
495 \c{QWindowPrivate::positionPolicy} is set to \c{QWindowPrivate::WindowFrameInclusive}. -
496 This means the position includes the window frame, whose size is at this point -
497 unknown and the geometry's topleft point is the position of the window frame. -
498 \endlist -
499 -
500 Apart from the auto-tests (\c{tests/auto/gui/kernel/qwindow}, -
501 \c{tests/auto/gui/kernel/qguiapplication} and \c{tests/auto/widgets/kernel/qwidget}), -
502 there are a number of manual tests and examples that can help testing a platform plugin: -
503 -
504 \list 1 -
505 \li \c{examples/qpa/windows}: Basic \c{QWindow} creation. -
506 \li \c{examples/opengl/hellowindow}: Basic Open GL windows. -
507 \li \c{tests/manual/windowflags}: Tests setting the window flags. -
508 \li \c{tests/manual/windowgeometry} Tests setting the window geometry. -
509 \li \c{tests/manual/windowmodality} Tests setting the window modality. -
510 \li \c{tests/manual/widgetgrab} Tests mouse grab and dialogs. -
511 \endlist -
512 -
513 \sa QBackingStore, QWindow -
514*/ -
515 -
516QT_END_NAMESPACE -
517 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial