summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-02-09 13:46:28 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-09 21:35:52 +0100
commit41914453d38d01b9b69e16ccee69444d1a304bf7 (patch)
tree9b29cc8fa4d1bca01f9ad24ebc380b1e3307690d /src
parentbe98fa32c7d56ea91359b647a329356fa44eca04 (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')
-rw-r--r--src/gui/image/image.pri1
-rw-r--r--src/gui/image/qpixmap.cpp13
-rw-r--r--src/gui/image/qpixmap_qpa.cpp53
-rw-r--r--src/gui/kernel/qscreen.cpp48
-rw-r--r--src/gui/kernel/qscreen.h3
5 files changed, 64 insertions, 54 deletions
diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri
index dd7b665ecc..f83e7e60c9 100644
--- a/src/gui/image/image.pri
+++ b/src/gui/image/image.pri
@@ -45,7 +45,6 @@ SOURCES += \
image/qimagepixmapcleanuphooks.cpp \
image/qvolatileimage.cpp
-SOURCES += image/qpixmap_qpa.cpp
win32: SOURCES += image/qpixmap_win.cpp
SOURCES += image/qvolatileimagedata.cpp
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index f1a06fa33c..16945edc90 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -1613,9 +1613,22 @@ QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionF
\warning In general, grabbing an area outside the screen is not
safe. This depends on the underlying window system.
+ \warning The function is deprecated in Qt 5.0 since there might be
+ platform plugins in which window system identifiers (\c WId)
+ are local to a screen. Use QScreen::grabWindow() instead.
+
\sa grabWidget(), {Screenshot Example}
+ \sa QScreen
+ \deprecated
*/
+QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
+{
+ qWarning("%s is deprecated, use QScreen::grabWindow() instead."
+ " Defaulting to primary screen.", Q_FUNC_INFO);
+ return QGuiApplication::primaryScreen()->grabWindow(window, x, y, w, h);
+}
+
/*!
\internal
*/
diff --git a/src/gui/image/qpixmap_qpa.cpp b/src/gui/image/qpixmap_qpa.cpp
deleted file mode 100644
index 162c5f5286..0000000000
--- a/src/gui/image/qpixmap_qpa.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** 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, Nokia gives you certain additional
-** rights. These rights are described in the Nokia 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.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qpixmap.h>
-#include <qscreen.h>
-#include <private/qguiapplication_p.h>
-
-QT_BEGIN_NAMESPACE
-
-QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
-{
- return QGuiApplication::primaryScreen()->handle()->grabWindow(window, x, y, w, h);
-}
-
-QT_END_NAMESPACE
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
diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h
index f73cd0836f..111e10d340 100644
--- a/src/gui/kernel/qscreen.h
+++ b/src/gui/kernel/qscreen.h
@@ -61,6 +61,7 @@ class QPlatformScreen;
class QScreenPrivate;
class QWindow;
class QRect;
+class QPixmap;
class Q_GUI_EXPORT QScreen : public QObject
{
@@ -124,6 +125,8 @@ public:
bool isPortrait(Qt::ScreenOrientation orientation);
bool isLandscape(Qt::ScreenOrientation orientation);
+ QPixmap grabWindow(WId window, int x, int y, int w, int h) const;
+
Q_SIGNALS:
void sizeChanged(const QSize &size);
void geometryChanged(const QRect &geometry);