diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-02-09 13:46:28 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-09 21:35:52 +0100 |
commit | 41914453d38d01b9b69e16ccee69444d1a304bf7 (patch) | |
tree | 9b29cc8fa4d1bca01f9ad24ebc380b1e3307690d /src/gui/kernel/qscreen.cpp | |
parent | be98fa32c7d56ea91359b647a329356fa44eca04 (diff) |
Introduce QScreen::grabWindow(), deprecate QPixmap::grabWindow().
WId can be local to a screen.
Change-Id: I09ca71313836a34dbf33289b254c80207a956bb1
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/gui/kernel/qscreen.cpp')
-rw-r--r-- | src/gui/kernel/qscreen.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index 67eb991b19..da0716b7d5 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -41,6 +41,7 @@ #include "qscreen.h" #include "qscreen_p.h" +#include "qpixmap.h" #include "qplatformscreen_qpa.h" #include <QtCore/private/qobject_p.h> @@ -542,4 +543,51 @@ void QScreenPrivate::updatePrimaryOrientation() primaryOrientation = geometry.width() >= geometry.height() ? Qt::LandscapeOrientation : Qt::PortraitOrientation; } +/*! + Creates and returns a pixmap constructed by grabbing the contents + of the given \a window restricted by QRect(\a x, \a y, \a width, + \a height). + + The arguments (\a{x}, \a{y}) specify the offset in the window, + whereas (\a{width}, \a{height}) specify the area to be copied. If + \a width is negative, the function copies everything to the right + border of the window. If \a height is negative, the function + copies everything to the bottom of the window. + + The window system identifier (\c WId) can be retrieved using the + QWidget::winId() function. The rationale for using a window + identifier and not a QWidget, is to enable grabbing of windows + that are not part of the application, window system frames, and so + on. + + The grabWindow() function grabs pixels from the screen, not from + the window, i.e. if there is another window partially or entirely + over the one you grab, you get pixels from the overlying window, + too. The mouse cursor is generally not grabbed. + + Note on X11 that if the given \a window doesn't have the same depth + as the root window, and another window partially or entirely + obscures the one you grab, you will \e not get pixels from the + overlying window. The contents of the obscured areas in the + pixmap will be undefined and uninitialized. + + On Windows Vista and above grabbing a layered window, which is + created by setting the Qt::WA_TranslucentBackground attribute, will + not work. Instead grabbing the desktop widget should work. + + \warning In general, grabbing an area outside the screen is not + safe. This depends on the underlying window system. + \since 5.0 +*/ + +QPixmap QScreen::grabWindow(WId window, int x, int y, int w, int h) const +{ + const QPlatformScreen *platformScreen = handle(); + if (!platformScreen) { + qWarning("%s invoked with handle==0", Q_FUNC_INFO); + return QPixmap(); + } + return platformScreen->grabWindow(window, x, y, w, h); +} + QT_END_NAMESPACE |