source: trunk/src/gui/image/qpixmap_qws.cpp@ 621

Last change on this file since 621 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
52QT_BEGIN_NAMESPACE
53
54QPixmap 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
115QRgb* QPixmap::clut() const
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
125int QPixmap::numCols() const
126{
127 return colorCount();
128}
129
130int QPixmap::colorCount() const
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
140const 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
150int QPixmap::qwsBytesPerLine() const
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
160QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.