author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 23 Jun 2010 19:07:03 +0300 | |
changeset 29 | b72c6db6890b |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
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 |
||
52 |
QT_BEGIN_NAMESPACE |
|
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; |
|
70 |
QDesktopWidget *desktop = QApplication::desktop(); |
|
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); |
|
96 |
QWSDisplay::ungrab(); |
|
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 |
||
115 |
QRgb* QPixmap::clut() const |
|
116 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
if (data && data->classId() == QPixmapData::RasterClass) { |
0 | 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 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
return colorCount(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
int QPixmap::colorCount() const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
if (data && data->classId() == QPixmapData::RasterClass) { |
0 | 133 |
const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
return d->image.colorCount(); |
0 | 135 |
} |
136 |
||
137 |
return 0; |
|
138 |
} |
|
139 |
||
140 |
const uchar* QPixmap::qwsBits() const |
|
141 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
if (data && data->classId() == QPixmapData::RasterClass) { |
0 | 143 |
const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); |
144 |
return d->image.bits(); |
|
145 |
} |
|
146 |
||
147 |
return 0; |
|
148 |
} |
|
149 |
||
150 |
int QPixmap::qwsBytesPerLine() const |
|
151 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
if (data && data->classId() == QPixmapData::RasterClass) { |
0 | 153 |
const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data()); |
154 |
return d->image.bytesPerLine(); |
|
155 |
} |
|
156 |
||
157 |
return 0; |
|
158 |
} |
|
159 |
||
160 |
QT_END_NAMESPACE |