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>
This commit is contained in:
parent
be98fa32c7
commit
41914453d3
@ -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
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user