Qt 4.8
qpixmap_qws.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 <qpixmap.h>
43 #include <qapplication.h>
44 #include <qwidget.h>
45 #include <qdesktopwidget.h>
46 #include <qscreen_qws.h>
47 #include <qwsdisplay_qws.h>
48 #include <private/qdrawhelper_p.h>
49 #include <private/qpixmap_raster_p.h>
50 
51 
53 
54 QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
55 {
56  QWidget *widget = QWidget::find(window);
57  if (!widget)
58  return QPixmap();
59 
60  QRect grabRect = widget->frameGeometry();
61  if (!widget->isWindow())
62  grabRect.translate(widget->parentWidget()->mapToGlobal(QPoint()));
63  if (w < 0)
64  w = widget->width() - x;
65  if (h < 0)
66  h = widget->height() - y;
67  grabRect &= QRect(x, y, w, h).translated(widget->mapToGlobal(QPoint()));
68 
69  QScreen *screen = qt_screen;
71  if (!desktop)
72  return QPixmap();
73  if (desktop->numScreens() > 1) {
74  const int screenNo = desktop->screenNumber(widget);
75  if (screenNo != -1)
76  screen = qt_screen->subScreens().at(screenNo);
77  grabRect = grabRect.translated(-screen->region().boundingRect().topLeft());
78  }
79 
80  if (screen->pixelFormat() == QImage::Format_Invalid) {
81  qWarning("QPixmap::grabWindow(): Unable to copy pixels from framebuffer");
82  return QPixmap();
83  }
84 
85  if (screen->isTransformed()) {
86  const QSize screenSize(screen->width(), screen->height());
87  grabRect = screen->mapToDevice(grabRect, screenSize);
88  }
89 
90  QWSDisplay::grab(false);
91  QPixmap pixmap;
92  QImage img(screen->base(),
93  screen->deviceWidth(), screen->deviceHeight(),
94  screen->linestep(), screen->pixelFormat());
95  img = img.copy(grabRect);
97 
98  if (screen->isTransformed()) {
99  QMatrix matrix;
100  switch (screen->transformOrientation()) {
101  case 1: matrix.rotate(90); break;
102  case 2: matrix.rotate(180); break;
103  case 3: matrix.rotate(270); break;
104  default: break;
105  }
106  img = img.transformed(matrix);
107  }
108 
109  if (screen->pixelType() == QScreen::BGRPixel)
110  img = img.rgbSwapped();
111 
112  return QPixmap::fromImage(img);
113 }
114 
116 {
117  if (data && data->classId() == QPixmapData::RasterClass) {
118  const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
119  return d->image.colorTable().data();
120  }
121 
122  return 0;
123 }
124 
125 int QPixmap::numCols() const
126 {
127  return colorCount();
128 }
129 
131 {
132  if (data && data->classId() == QPixmapData::RasterClass) {
133  const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
134  return d->image.colorCount();
135  }
136 
137  return 0;
138 }
139 
140 const uchar* QPixmap::qwsBits() const
141 {
142  if (data && data->classId() == QPixmapData::RasterClass) {
143  const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
144  return d->image.bits();
145  }
146 
147  return 0;
148 }
149 
151 {
152  if (data && data->classId() == QPixmapData::RasterClass) {
153  const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
154  return d->image.bytesPerLine();
155  }
156 
157  return 0;
158 }
159 
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
unsigned int QRgb
Definition: qrgb.h:53
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
unsigned long WId
Definition: qwindowdefs.h:119
int height() const
Returns the logical height of the framebuffer in pixels.
Definition: qscreen_qws.h:228
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
QRgb * clut() const
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QRect frameGeometry
geometry of the widget relative to its parent including any window frame
Definition: qwidget.h:159
QT_DEPRECATED int numCols() const
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int deviceWidth() const
Returns the physical width of the framebuffer device in pixels.
Definition: qscreen_qws.h:233
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
const uchar * qwsBits() const
virtual QSize mapToDevice(const QSize &) const
Maps the given size from the coordinate space used by the application to the framebuffer coordinate s...
virtual QRegion region() const
Returns the region covered by this screen driver.
Definition: qscreen_qws.h:284
unsigned char uchar
Definition: qglobal.h:994
int width() const
Returns the logical width of the framebuffer in pixels.
Definition: qscreen_qws.h:227
NSWindow * window
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
PixelType pixelType() const
Returns the pixel storage format of the screen.
Definition: qscreen_qws.h:231
int linestep() const
Returns the length of each scanline of the framebuffer in bytes.
Definition: qscreen_qws.h:232
QMatrix & rotate(qreal a)
Rotates the coordinate system the given degrees counterclockwise.
Definition: qmatrix.cpp:990
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QWidget * find(WId)
Returns a pointer to the widget with window identifer/handle id.
Definition: qwidget.cpp:2517
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
ClassId classId() const
int numScreens() const
static void grab()
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
uchar * base() const
Returns a pointer to the beginning of the framebuffer.
Definition: qscreen_qws.h:235
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
QImage::Format pixelFormat() const
Returns the pixel format of the screen, or QImage::Format_Invalid if the pixel format is not a suppor...
int deviceHeight() const
Returns the full height of the framebuffer device in pixels.
Definition: qscreen_qws.h:234
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656
virtual QList< QScreen * > subScreens() const
Definition: qscreen_qws.h:283
virtual bool isTransformed() const
Returns true if the screen is transformed (for instance, rotated 90 degrees); otherwise returns false...
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
virtual int transformOrientation() const
Returns the current rotation as an integer value.
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int colorCount() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
int screenNumber(const QWidget *widget=0) const
static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1)
Creates and returns a pixmap constructed by grabbing the contents of the given window restricted by Q...
static void ungrab()
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
QVector< QRgb > colorTable() const
Returns a list of the colors contained in the image&#39;s color table, or an empty list if the image does...
Definition: qimage.cpp:1770
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
int qwsBytesPerLine() const