author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 3 | 41300fa6a67c |
child 19 | fcece45ef507 |
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 <qglobal.h> |
|
43 |
||
44 |
#include "qpixmap.h" |
|
45 |
#include "qpixmapdata_p.h" |
|
46 |
#include "qimagepixmapcleanuphooks_p.h" |
|
47 |
||
48 |
#include "qbitmap.h" |
|
49 |
#include "qcolormap.h" |
|
50 |
#include "qimage.h" |
|
51 |
#include "qwidget.h" |
|
52 |
#include "qpainter.h" |
|
53 |
#include "qdatastream.h" |
|
54 |
#include "qbuffer.h" |
|
55 |
#include "qapplication.h" |
|
56 |
#include <private/qapplication_p.h> |
|
57 |
#include <private/qgraphicssystem_p.h> |
|
58 |
#include <private/qwidget_p.h> |
|
59 |
#include "qevent.h" |
|
60 |
#include "qfile.h" |
|
61 |
#include "qfileinfo.h" |
|
62 |
#include "qpixmapcache.h" |
|
63 |
#include "qdatetime.h" |
|
64 |
#include "qimagereader.h" |
|
65 |
#include "qimagewriter.h" |
|
66 |
#include "qpaintengine.h" |
|
67 |
#include "qthread.h" |
|
68 |
||
69 |
#ifdef Q_WS_MAC |
|
70 |
# include "private/qt_mac_p.h" |
|
71 |
# include "private/qpixmap_mac_p.h" |
|
72 |
#endif |
|
73 |
||
74 |
#if defined(Q_WS_X11) |
|
75 |
# include "qx11info_x11.h" |
|
76 |
# include <private/qt_x11_p.h> |
|
77 |
# include <private/qpixmap_x11_p.h> |
|
78 |
#endif |
|
79 |
||
80 |
#if defined(Q_OS_SYMBIAN) |
|
81 |
# include <private/qt_s60_p.h> |
|
82 |
#endif |
|
83 |
||
84 |
#include "qpixmap_raster_p.h" |
|
85 |
||
86 |
QT_BEGIN_NAMESPACE |
|
87 |
||
88 |
// ### Qt 5: remove |
|
89 |
Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap) |
|
90 |
{ |
|
91 |
return pixmap.cacheKey(); |
|
92 |
} |
|
93 |
||
94 |
static bool qt_pixmap_thread_test() |
|
95 |
{ |
|
96 |
if (!qApp) { |
|
97 |
qFatal("QPixmap: Must construct a QApplication before a QPaintDevice"); |
|
98 |
return false; |
|
99 |
} |
|
100 |
#ifndef Q_WS_WIN |
|
101 |
if (qApp->thread() != QThread::currentThread()) { |
|
102 |
qWarning("QPixmap: It is not safe to use pixmaps outside the GUI thread"); |
|
103 |
return false; |
|
104 |
} |
|
105 |
#endif |
|
106 |
return true; |
|
107 |
} |
|
108 |
||
109 |
void QPixmap::init(int w, int h, Type type) |
|
110 |
{ |
|
111 |
init(w, h, int(type)); |
|
112 |
} |
|
113 |
||
114 |
void QPixmap::init(int w, int h, int type) |
|
115 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
if ((w > 0 && h > 0) || type == QPixmapData::BitmapType) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
data = QPixmapData::create(w, h, (QPixmapData::PixelType) type); |
0 | 118 |
else |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
data = 0; |
0 | 120 |
} |
121 |
||
122 |
/*! |
|
123 |
\enum QPixmap::ColorMode |
|
124 |
||
125 |
\compat |
|
126 |
||
127 |
This enum type defines the color modes that exist for converting |
|
128 |
QImage objects to QPixmap. It is provided here for compatibility |
|
129 |
with earlier versions of Qt. |
|
130 |
||
131 |
Use Qt::ImageConversionFlags instead. |
|
132 |
||
133 |
\value Auto Select \c Color or \c Mono on a case-by-case basis. |
|
134 |
\value Color Always create colored pixmaps. |
|
135 |
\value Mono Always create bitmaps. |
|
136 |
*/ |
|
137 |
||
138 |
/*! |
|
139 |
Constructs a null pixmap. |
|
140 |
||
141 |
\sa isNull() |
|
142 |
*/ |
|
143 |
||
144 |
QPixmap::QPixmap() |
|
145 |
: QPaintDevice() |
|
146 |
{ |
|
147 |
(void) qt_pixmap_thread_test(); |
|
148 |
init(0, 0, QPixmapData::PixmapType); |
|
149 |
} |
|
150 |
||
151 |
/*! |
|
152 |
\fn QPixmap::QPixmap(int width, int height) |
|
153 |
||
154 |
Constructs a pixmap with the given \a width and \a height. If |
|
155 |
either \a width or \a height is zero, a null pixmap is |
|
156 |
constructed. |
|
157 |
||
158 |
\warning This will create a QPixmap with uninitialized data. Call |
|
159 |
fill() to fill the pixmap with an appropriate color before drawing |
|
160 |
onto it with QPainter. |
|
161 |
||
162 |
\sa isNull() |
|
163 |
*/ |
|
164 |
||
165 |
QPixmap::QPixmap(int w, int h) |
|
166 |
: QPaintDevice() |
|
167 |
{ |
|
168 |
if (!qt_pixmap_thread_test()) |
|
169 |
init(0, 0, QPixmapData::PixmapType); |
|
170 |
else |
|
171 |
init(w, h, QPixmapData::PixmapType); |
|
172 |
} |
|
173 |
||
174 |
/*! |
|
175 |
\overload |
|
176 |
||
177 |
Constructs a pixmap of the given \a size. |
|
178 |
||
179 |
\warning This will create a QPixmap with uninitialized data. Call |
|
180 |
fill() to fill the pixmap with an appropriate color before drawing |
|
181 |
onto it with QPainter. |
|
182 |
*/ |
|
183 |
||
184 |
QPixmap::QPixmap(const QSize &size) |
|
185 |
: QPaintDevice() |
|
186 |
{ |
|
187 |
if (!qt_pixmap_thread_test()) |
|
188 |
init(0, 0, QPixmapData::PixmapType); |
|
189 |
else |
|
190 |
init(size.width(), size.height(), QPixmapData::PixmapType); |
|
191 |
} |
|
192 |
||
193 |
/*! |
|
194 |
\internal |
|
195 |
*/ |
|
196 |
QPixmap::QPixmap(const QSize &s, Type type) |
|
197 |
{ |
|
198 |
if (!qt_pixmap_thread_test()) |
|
199 |
init(0, 0, type); |
|
200 |
else |
|
201 |
init(s.width(), s.height(), type); |
|
202 |
} |
|
203 |
||
204 |
/*! |
|
205 |
\internal |
|
206 |
*/ |
|
207 |
QPixmap::QPixmap(const QSize &s, int type) |
|
208 |
{ |
|
209 |
if (!qt_pixmap_thread_test()) |
|
210 |
init(0, 0, static_cast<QPixmapData::PixelType>(type)); |
|
211 |
else |
|
212 |
init(s.width(), s.height(), static_cast<QPixmapData::PixelType>(type)); |
|
213 |
} |
|
214 |
||
215 |
/*! |
|
216 |
\internal |
|
217 |
*/ |
|
218 |
QPixmap::QPixmap(QPixmapData *d) |
|
219 |
: QPaintDevice(), data(d) |
|
220 |
{ |
|
221 |
} |
|
222 |
||
223 |
/*! |
|
224 |
Constructs a pixmap from the file with the given \a fileName. If the |
|
225 |
file does not exist or is of an unknown format, the pixmap becomes a |
|
226 |
null pixmap. |
|
227 |
||
228 |
The loader attempts to read the pixmap using the specified \a |
|
229 |
format. If the \a format is not specified (which is the default), |
|
230 |
the loader probes the file for a header to guess the file format. |
|
231 |
||
232 |
The file name can either refer to an actual file on disk or to |
|
233 |
one of the application's embedded resources. See the |
|
234 |
\l{resources.html}{Resource System} overview for details on how |
|
235 |
to embed images and other resource files in the application's |
|
236 |
executable. |
|
237 |
||
238 |
If the image needs to be modified to fit in a lower-resolution |
|
239 |
result (e.g. converting from 32-bit to 8-bit), use the \a |
|
240 |
flags to control the conversion. |
|
241 |
||
242 |
The \a fileName, \a format and \a flags parameters are |
|
243 |
passed on to load(). This means that the data in \a fileName is |
|
244 |
not compiled into the binary. If \a fileName contains a relative |
|
245 |
path (e.g. the filename only) the relevant file must be found |
|
246 |
relative to the runtime working directory. |
|
247 |
||
248 |
\sa {QPixmap#Reading and Writing Image Files}{Reading and Writing |
|
249 |
Image Files} |
|
250 |
*/ |
|
251 |
||
252 |
QPixmap::QPixmap(const QString& fileName, const char *format, Qt::ImageConversionFlags flags) |
|
253 |
: QPaintDevice() |
|
254 |
{ |
|
255 |
init(0, 0, QPixmapData::PixmapType); |
|
256 |
if (!qt_pixmap_thread_test()) |
|
257 |
return; |
|
258 |
||
259 |
load(fileName, format, flags); |
|
260 |
} |
|
261 |
||
262 |
/*! |
|
263 |
Constructs a pixmap that is a copy of the given \a pixmap. |
|
264 |
||
265 |
\sa copy() |
|
266 |
*/ |
|
267 |
||
268 |
QPixmap::QPixmap(const QPixmap &pixmap) |
|
269 |
: QPaintDevice() |
|
270 |
{ |
|
271 |
if (!qt_pixmap_thread_test()) { |
|
272 |
init(0, 0, QPixmapData::PixmapType); |
|
273 |
return; |
|
274 |
} |
|
275 |
if (pixmap.paintingActive()) { // make a deep copy |
|
276 |
operator=(pixmap.copy()); |
|
277 |
} else { |
|
278 |
data = pixmap.data; |
|
279 |
} |
|
280 |
} |
|
281 |
||
282 |
/*! |
|
283 |
Constructs a pixmap from the given \a xpm data, which must be a |
|
284 |
valid XPM image. |
|
285 |
||
286 |
Errors are silently ignored. |
|
287 |
||
288 |
Note that it's possible to squeeze the XPM variable a little bit |
|
289 |
by using an unusual declaration: |
|
290 |
||
291 |
\snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 0 |
|
292 |
||
293 |
The extra \c const makes the entire definition read-only, which is |
|
294 |
slightly more efficient (for example, when the code is in a shared |
|
295 |
library) and ROMable when the application is to be stored in ROM. |
|
296 |
*/ |
|
297 |
#ifndef QT_NO_IMAGEFORMAT_XPM |
|
298 |
QPixmap::QPixmap(const char * const xpm[]) |
|
299 |
: QPaintDevice() |
|
300 |
{ |
|
301 |
init(0, 0, QPixmapData::PixmapType); |
|
302 |
if (!xpm) |
|
303 |
return; |
|
304 |
||
305 |
QImage image(xpm); |
|
306 |
if (!image.isNull()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
if (data && data->pixelType() == QPixmapData::BitmapType) |
0 | 308 |
*this = QBitmap::fromImage(image); |
309 |
else |
|
310 |
*this = fromImage(image); |
|
311 |
} |
|
312 |
} |
|
313 |
#endif |
|
314 |
||
315 |
||
316 |
/*! |
|
317 |
Destroys the pixmap. |
|
318 |
*/ |
|
319 |
||
320 |
QPixmap::~QPixmap() |
|
321 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again |
0 | 323 |
} |
324 |
||
325 |
/*! |
|
326 |
\internal |
|
327 |
*/ |
|
328 |
int QPixmap::devType() const |
|
329 |
{ |
|
330 |
return QInternal::Pixmap; |
|
331 |
} |
|
332 |
||
333 |
/*! |
|
334 |
\fn QPixmap QPixmap::copy(int x, int y, int width, int height) const |
|
335 |
\overload |
|
336 |
||
337 |
Returns a deep copy of the subset of the pixmap that is specified |
|
338 |
by the rectangle QRect( \a x, \a y, \a width, \a height). |
|
339 |
*/ |
|
340 |
||
341 |
/*! |
|
342 |
\fn QPixmap QPixmap::copy(const QRect &rectangle) const |
|
343 |
||
344 |
Returns a deep copy of the subset of the pixmap that is specified |
|
345 |
by the given \a rectangle. For more information on deep copies, |
|
346 |
see the \l {Implicit Data Sharing} documentation. |
|
347 |
||
348 |
If the given \a rectangle is empty, the whole image is copied. |
|
349 |
||
350 |
\sa operator=(), QPixmap(), {QPixmap#Pixmap |
|
351 |
Transformations}{Pixmap Transformations} |
|
352 |
*/ |
|
353 |
QPixmap QPixmap::copy(const QRect &rect) const |
|
354 |
{ |
|
355 |
if (isNull()) |
|
356 |
return QPixmap(); |
|
357 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
358 |
QRect r(0, 0, width(), height()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
359 |
if (!rect.isEmpty()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
360 |
r = r.intersected(rect); |
0 | 361 |
|
362 |
QPixmapData *d = data->createCompatiblePixmapData(); |
|
363 |
d->copy(data.data(), r); |
|
364 |
return QPixmap(d); |
|
365 |
} |
|
366 |
||
367 |
/*! |
|
368 |
\fn QPixmap::scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed) |
|
369 |
\since 4.6 |
|
370 |
||
371 |
This convenience function is equivalent to calling QPixmap::scroll(\a dx, |
|
372 |
\a dy, QRect(\a x, \a y, \a width, \a height), \a exposed). |
|
373 |
||
374 |
\sa QWidget::scroll(), QGraphicsItem::scroll() |
|
375 |
*/ |
|
376 |
||
377 |
/*! |
|
378 |
\since 4.6 |
|
379 |
||
380 |
Scrolls the area \a rect of this pixmap by (\a dx, \a dy). The exposed |
|
381 |
region is left unchanged. You can optionally pass a pointer to an empty |
|
382 |
QRegion to get the region that is \a exposed by the scroll operation. |
|
383 |
||
384 |
\snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 2 |
|
385 |
||
386 |
You cannot scroll while there is an active painter on the pixmap. |
|
387 |
||
388 |
\sa QWidget::scroll(), QGraphicsItem::scroll() |
|
389 |
*/ |
|
390 |
void QPixmap::scroll(int dx, int dy, const QRect &rect, QRegion *exposed) |
|
391 |
{ |
|
392 |
if (isNull() || (dx == 0 && dy == 0)) |
|
393 |
return; |
|
394 |
QRect dest = rect & this->rect(); |
|
395 |
QRect src = dest.translated(-dx, -dy) & dest; |
|
396 |
if (src.isEmpty()) { |
|
397 |
if (exposed) |
|
398 |
*exposed += dest; |
|
399 |
return; |
|
400 |
} |
|
401 |
||
402 |
detach(); |
|
403 |
||
404 |
if (!data->scroll(dx, dy, src)) { |
|
405 |
// Fallback |
|
406 |
QPixmap pix = *this; |
|
407 |
QPainter painter(&pix); |
|
408 |
painter.setCompositionMode(QPainter::CompositionMode_Source); |
|
409 |
painter.drawPixmap(src.translated(dx, dy), *this, src); |
|
410 |
painter.end(); |
|
411 |
*this = pix; |
|
412 |
} |
|
413 |
||
414 |
if (exposed) { |
|
415 |
*exposed += dest; |
|
416 |
*exposed -= src.translated(dx, dy); |
|
417 |
} |
|
418 |
} |
|
419 |
||
420 |
/*! |
|
421 |
Assigns the given \a pixmap to this pixmap and returns a reference |
|
422 |
to this pixmap. |
|
423 |
||
424 |
\sa copy(), QPixmap() |
|
425 |
*/ |
|
426 |
||
427 |
QPixmap &QPixmap::operator=(const QPixmap &pixmap) |
|
428 |
{ |
|
429 |
if (paintingActive()) { |
|
430 |
qWarning("QPixmap::operator=: Cannot assign to pixmap during painting"); |
|
431 |
return *this; |
|
432 |
} |
|
433 |
if (pixmap.paintingActive()) { // make a deep copy |
|
434 |
*this = pixmap.copy(); |
|
435 |
} else { |
|
436 |
data = pixmap.data; |
|
437 |
} |
|
438 |
return *this; |
|
439 |
} |
|
440 |
||
441 |
/*! |
|
442 |
Returns the pixmap as a QVariant. |
|
443 |
*/ |
|
444 |
QPixmap::operator QVariant() const |
|
445 |
{ |
|
446 |
return QVariant(QVariant::Pixmap, this); |
|
447 |
} |
|
448 |
||
449 |
/*! |
|
450 |
\fn bool QPixmap::operator!() const |
|
451 |
||
452 |
Returns true if this is a null pixmap; otherwise returns false. |
|
453 |
||
454 |
\sa isNull() |
|
455 |
*/ |
|
456 |
||
457 |
/*! |
|
458 |
\fn QPixmap::operator QImage() const |
|
459 |
||
460 |
Returns the pixmap as a QImage. |
|
461 |
||
462 |
Use the toImage() function instead. |
|
463 |
*/ |
|
464 |
||
465 |
/*! |
|
466 |
Converts the pixmap to a QImage. Returns a null image if the |
|
467 |
conversion fails. |
|
468 |
||
469 |
If the pixmap has 1-bit depth, the returned image will also be 1 |
|
470 |
bit deep. Images with more bits will be returned in a format |
|
471 |
closely represents the underlying system. Usually this will be |
|
472 |
QImage::Format_ARGB32_Premultiplied for pixmaps with an alpha and |
|
473 |
QImage::Format_RGB32 or QImage::Format_RGB16 for pixmaps without |
|
474 |
alpha. |
|
475 |
||
476 |
Note that for the moment, alpha masks on monochrome images are |
|
477 |
ignored. |
|
478 |
||
479 |
\sa fromImage(), {QImage#Image Formats}{Image Formats} |
|
480 |
*/ |
|
481 |
QImage QPixmap::toImage() const |
|
482 |
{ |
|
483 |
if (isNull()) |
|
484 |
return QImage(); |
|
485 |
||
486 |
return data->toImage(); |
|
487 |
} |
|
488 |
||
489 |
/*! |
|
490 |
\fn QMatrix QPixmap::trueMatrix(const QTransform &matrix, int width, int height) |
|
491 |
||
492 |
Returns the actual matrix used for transforming a pixmap with the |
|
493 |
given \a width, \a height and \a matrix. |
|
494 |
||
495 |
When transforming a pixmap using the transformed() function, the |
|
496 |
transformation matrix is internally adjusted to compensate for |
|
497 |
unwanted translation, i.e. transformed() returns the smallest |
|
498 |
pixmap containing all transformed points of the original |
|
499 |
pixmap. This function returns the modified matrix, which maps |
|
500 |
points correctly from the original pixmap into the new pixmap. |
|
501 |
||
502 |
\sa transformed(), {QPixmap#Pixmap Transformations}{Pixmap |
|
503 |
Transformations} |
|
504 |
*/ |
|
505 |
QTransform QPixmap::trueMatrix(const QTransform &m, int w, int h) |
|
506 |
{ |
|
507 |
return QImage::trueMatrix(m, w, h); |
|
508 |
} |
|
509 |
||
510 |
/*! |
|
511 |
\overload |
|
512 |
||
513 |
This convenience function loads the matrix \a m into a |
|
514 |
QTransform and calls the overloaded function with the |
|
515 |
QTransform and the width \a w and the height \a h. |
|
516 |
*/ |
|
517 |
QMatrix QPixmap::trueMatrix(const QMatrix &m, int w, int h) |
|
518 |
{ |
|
519 |
return trueMatrix(QTransform(m), w, h).toAffine(); |
|
520 |
} |
|
521 |
||
522 |
||
523 |
/*! |
|
524 |
\fn bool QPixmap::isQBitmap() const |
|
525 |
||
526 |
Returns true if this is a QBitmap; otherwise returns false. |
|
527 |
*/ |
|
528 |
||
529 |
bool QPixmap::isQBitmap() const |
|
530 |
{ |
|
531 |
return data->type == QPixmapData::BitmapType; |
|
532 |
} |
|
533 |
||
534 |
/*! |
|
535 |
\fn bool QPixmap::isNull() const |
|
536 |
||
537 |
Returns true if this is a null pixmap; otherwise returns false. |
|
538 |
||
539 |
A null pixmap has zero width, zero height and no contents. You |
|
540 |
cannot draw in a null pixmap. |
|
541 |
*/ |
|
542 |
bool QPixmap::isNull() const |
|
543 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
544 |
return !data || data->isNull(); |
0 | 545 |
} |
546 |
||
547 |
/*! |
|
548 |
\fn int QPixmap::width() const |
|
549 |
||
550 |
Returns the width of the pixmap. |
|
551 |
||
552 |
\sa size(), {QPixmap#Pixmap Information}{Pixmap Information} |
|
553 |
*/ |
|
554 |
int QPixmap::width() const |
|
555 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
556 |
return data ? data->width() : 0; |
0 | 557 |
} |
558 |
||
559 |
/*! |
|
560 |
\fn int QPixmap::height() const |
|
561 |
||
562 |
Returns the height of the pixmap. |
|
563 |
||
564 |
\sa size(), {QPixmap#Pixmap Information}{Pixmap Information} |
|
565 |
*/ |
|
566 |
int QPixmap::height() const |
|
567 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
568 |
return data ? data->height() : 0; |
0 | 569 |
} |
570 |
||
571 |
/*! |
|
572 |
\fn QSize QPixmap::size() const |
|
573 |
||
574 |
Returns the size of the pixmap. |
|
575 |
||
576 |
\sa width(), height(), {QPixmap#Pixmap Information}{Pixmap |
|
577 |
Information} |
|
578 |
*/ |
|
579 |
QSize QPixmap::size() const |
|
580 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
581 |
return data ? QSize(data->width(), data->height()) : QSize(); |
0 | 582 |
} |
583 |
||
584 |
/*! |
|
585 |
\fn QRect QPixmap::rect() const |
|
586 |
||
587 |
Returns the pixmap's enclosing rectangle. |
|
588 |
||
589 |
\sa {QPixmap#Pixmap Information}{Pixmap Information} |
|
590 |
*/ |
|
591 |
QRect QPixmap::rect() const |
|
592 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
593 |
return data ? QRect(0, 0, data->width(), data->height()) : QRect(); |
0 | 594 |
} |
595 |
||
596 |
/*! |
|
597 |
\fn int QPixmap::depth() const |
|
598 |
||
599 |
Returns the depth of the pixmap. |
|
600 |
||
601 |
The pixmap depth is also called bits per pixel (bpp) or bit planes |
|
602 |
of a pixmap. A null pixmap has depth 0. |
|
603 |
||
604 |
\sa defaultDepth(), {QPixmap#Pixmap Information}{Pixmap |
|
605 |
Information} |
|
606 |
*/ |
|
607 |
int QPixmap::depth() const |
|
608 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
609 |
return data ? data->depth() : 0; |
0 | 610 |
} |
611 |
||
612 |
/*! |
|
613 |
\fn void QPixmap::resize(const QSize &size) |
|
614 |
\overload |
|
615 |
\compat |
|
616 |
||
617 |
Use QPixmap::copy() instead to get the pixmap with the new size. |
|
618 |
||
619 |
\oldcode |
|
620 |
pixmap.resize(size); |
|
621 |
\newcode |
|
622 |
pixmap = pixmap.copy(QRect(QPoint(0, 0), size)); |
|
623 |
\endcode |
|
624 |
*/ |
|
625 |
#ifdef QT3_SUPPORT |
|
626 |
void QPixmap::resize_helper(const QSize &s) |
|
627 |
{ |
|
628 |
int w = s.width(); |
|
629 |
int h = s.height(); |
|
630 |
if (w < 1 || h < 1) { |
|
631 |
*this = QPixmap(); |
|
632 |
return; |
|
633 |
} |
|
634 |
||
635 |
if (size() == s) |
|
636 |
return; |
|
637 |
||
638 |
// Create new pixmap |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
639 |
QPixmap pm(QSize(w, h), data ? data->type : QPixmapData::PixmapType); |
0 | 640 |
bool uninit = false; |
641 |
#if defined(Q_WS_X11) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
642 |
QX11PixmapData *x11Data = data && data->classId() == QPixmapData::X11Class ? static_cast<QX11PixmapData*>(data.data()) : 0; |
0 | 643 |
if (x11Data) { |
644 |
pm.x11SetScreen(x11Data->xinfo.screen()); |
|
645 |
uninit = x11Data->flags & QX11PixmapData::Uninitialized; |
|
646 |
} |
|
647 |
#elif defined(Q_WS_MAC) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
QMacPixmapData *macData = data && data->classId() == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; |
0 | 649 |
if (macData) |
650 |
uninit = macData->uninit; |
|
651 |
#endif |
|
652 |
if (!uninit && !isNull()) { |
|
653 |
// Copy old pixmap |
|
654 |
if (hasAlphaChannel()) |
|
655 |
pm.fill(Qt::transparent); |
|
656 |
QPainter p(&pm); |
|
657 |
p.drawPixmap(0, 0, *this, 0, 0, qMin(width(), w), qMin(height(), h)); |
|
658 |
} |
|
659 |
||
660 |
#if defined(Q_WS_X11) |
|
661 |
if (x11Data && x11Data->x11_mask) { |
|
662 |
QX11PixmapData *pmData = static_cast<QX11PixmapData*>(pm.data.data()); |
|
663 |
pmData->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display, |
|
664 |
RootWindow(x11Data->xinfo.display(), |
|
665 |
x11Data->xinfo.screen()), |
|
666 |
w, h, 1); |
|
667 |
GC gc = XCreateGC(X11->display, pmData->x11_mask, 0, 0); |
|
668 |
XCopyArea(X11->display, x11Data->x11_mask, pmData->x11_mask, gc, 0, 0, qMin(width(), w), qMin(height(), h), 0, 0); |
|
669 |
XFreeGC(X11->display, gc); |
|
670 |
} |
|
671 |
#endif |
|
672 |
*this = pm; |
|
673 |
} |
|
674 |
#endif |
|
675 |
||
676 |
/*! |
|
677 |
\fn void QPixmap::resize(int width, int height) |
|
678 |
\compat |
|
679 |
||
680 |
Use QPixmap::copy() instead to get the pixmap with the new size. |
|
681 |
||
682 |
\oldcode |
|
683 |
pixmap.resize(10, 20); |
|
684 |
\newcode |
|
685 |
pixmap = pixmap.copy(0, 0, 10, 20); |
|
686 |
\endcode |
|
687 |
*/ |
|
688 |
||
689 |
/*! |
|
690 |
\fn bool QPixmap::selfMask() const |
|
691 |
\compat |
|
692 |
||
693 |
Returns whether the pixmap is its own mask or not. |
|
694 |
||
695 |
This function is no longer relevant since the concept of self |
|
696 |
masking doesn't exists anymore. |
|
697 |
*/ |
|
698 |
||
699 |
/*! |
|
700 |
Sets a mask bitmap. |
|
701 |
||
702 |
This function merges the \a mask with the pixmap's alpha channel. A pixel |
|
703 |
value of 1 on the mask means the pixmap's pixel is unchanged; a value of 0 |
|
704 |
means the pixel is transparent. The mask must have the same size as this |
|
705 |
pixmap. |
|
706 |
||
707 |
Setting a null mask resets the mask, leaving the previously transparent |
|
708 |
pixels black. The effect of this function is undefined when the pixmap is |
|
709 |
being painted on. |
|
710 |
||
711 |
\warning This is potentially an expensive operation. |
|
712 |
||
713 |
\sa mask(), {QPixmap#Pixmap Transformations}{Pixmap Transformations}, |
|
714 |
QBitmap |
|
715 |
*/ |
|
716 |
void QPixmap::setMask(const QBitmap &mask) |
|
717 |
{ |
|
718 |
if (paintingActive()) { |
|
719 |
qWarning("QPixmap::setMask: Cannot set mask while pixmap is being painted on"); |
|
720 |
return; |
|
721 |
} |
|
722 |
||
723 |
if (!mask.isNull() && mask.size() != size()) { |
|
724 |
qWarning("QPixmap::setMask() mask size differs from pixmap size"); |
|
725 |
return; |
|
726 |
} |
|
727 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
728 |
if (isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
729 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
730 |
|
0 | 731 |
if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask |
732 |
return; |
|
733 |
||
734 |
detach(); |
|
735 |
data->setMask(mask); |
|
736 |
} |
|
737 |
||
738 |
#ifndef QT_NO_IMAGE_HEURISTIC_MASK |
|
739 |
/*! |
|
740 |
Creates and returns a heuristic mask for this pixmap. |
|
741 |
||
742 |
The function works by selecting a color from one of the corners |
|
743 |
and then chipping away pixels of that color, starting at all the |
|
744 |
edges. If \a clipTight is true (the default) the mask is just |
|
745 |
large enough to cover the pixels; otherwise, the mask is larger |
|
746 |
than the data pixels. |
|
747 |
||
748 |
The mask may not be perfect but it should be reasonable, so you |
|
749 |
can do things such as the following: |
|
750 |
||
751 |
\snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 1 |
|
752 |
||
753 |
This function is slow because it involves converting to/from a |
|
754 |
QImage, and non-trivial computations. |
|
755 |
||
756 |
\sa QImage::createHeuristicMask(), createMaskFromColor() |
|
757 |
*/ |
|
758 |
QBitmap QPixmap::createHeuristicMask(bool clipTight) const |
|
759 |
{ |
|
760 |
QBitmap m = QBitmap::fromImage(toImage().createHeuristicMask(clipTight)); |
|
761 |
return m; |
|
762 |
} |
|
763 |
#endif |
|
764 |
||
765 |
/*! |
|
766 |
Creates and returns a mask for this pixmap based on the given \a |
|
767 |
maskColor. If the \a mode is Qt::MaskInColor, all pixels matching the |
|
768 |
maskColor will be opaque. If \a mode is Qt::MaskOutColor, all pixels |
|
769 |
matching the maskColor will be transparent. |
|
770 |
||
771 |
This function is slow because it involves converting to/from a |
|
772 |
QImage. |
|
773 |
||
774 |
\sa createHeuristicMask(), QImage::createMaskFromColor() |
|
775 |
*/ |
|
776 |
QBitmap QPixmap::createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const |
|
777 |
{ |
|
778 |
QImage image = toImage().convertToFormat(QImage::Format_ARGB32); |
|
779 |
return QBitmap::fromImage(image.createMaskFromColor(maskColor.rgba(), mode)); |
|
780 |
} |
|
781 |
||
782 |
/*! \overload |
|
783 |
||
784 |
Creates and returns a mask for this pixmap based on the given \a |
|
785 |
maskColor. Same as calling createMaskFromColor(maskColor, |
|
786 |
Qt::MaskInColor) |
|
787 |
||
788 |
\sa createHeuristicMask(), QImage::createMaskFromColor() |
|
789 |
*/ |
|
790 |
QBitmap QPixmap::createMaskFromColor(const QColor &maskColor) const |
|
791 |
{ |
|
792 |
return createMaskFromColor(maskColor, Qt::MaskInColor); |
|
793 |
} |
|
794 |
||
795 |
/*! |
|
796 |
Loads a pixmap from the file with the given \a fileName. Returns |
|
797 |
true if the pixmap was successfully loaded; otherwise returns |
|
798 |
false. |
|
799 |
||
800 |
The loader attempts to read the pixmap using the specified \a |
|
801 |
format. If the \a format is not specified (which is the default), |
|
802 |
the loader probes the file for a header to guess the file format. |
|
803 |
||
804 |
The file name can either refer to an actual file on disk or to one |
|
805 |
of the application's embedded resources. See the |
|
806 |
\l{resources.html}{Resource System} overview for details on how to |
|
807 |
embed pixmaps and other resource files in the application's |
|
808 |
executable. |
|
809 |
||
810 |
If the data needs to be modified to fit in a lower-resolution |
|
811 |
result (e.g. converting from 32-bit to 8-bit), use the \a flags to |
|
812 |
control the conversion. |
|
813 |
||
814 |
Note that QPixmaps are automatically added to the QPixmapCache |
|
815 |
when loaded from a file; the key used is internal and can not |
|
816 |
be acquired. |
|
817 |
||
818 |
\sa loadFromData(), {QPixmap#Reading and Writing Image |
|
819 |
Files}{Reading and Writing Image Files} |
|
820 |
*/ |
|
821 |
||
822 |
bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConversionFlags flags) |
|
823 |
{ |
|
824 |
if (fileName.isEmpty()) |
|
825 |
return false; |
|
826 |
||
827 |
QFileInfo info(fileName); |
|
828 |
QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() + QLatin1Char('_') + QString::number(info.lastModified().toTime_t()) + QLatin1Char('_') + |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
829 |
QString::number(info.size()) + QLatin1Char('_') + QString::number(data ? data->pixelType() : QPixmapData::PixmapType); |
0 | 830 |
|
831 |
if (QPixmapCache::find(key, *this)) |
|
832 |
return true; |
|
833 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
834 |
bool ok; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
835 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
836 |
if (data) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
837 |
ok = data->fromFile(fileName, format, flags); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
838 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
839 |
QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, QPixmapData::PixmapType)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
840 |
ok = tmp->fromFile(fileName, format, flags); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
841 |
if (ok) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
842 |
data = tmp.take(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
843 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
844 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
845 |
if (ok) |
0 | 846 |
QPixmapCache::insert(key, *this); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
847 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
848 |
return ok; |
0 | 849 |
} |
850 |
||
851 |
/*! |
|
852 |
\fn bool QPixmap::loadFromData(const uchar *data, uint len, const char *format, Qt::ImageConversionFlags flags) |
|
853 |
||
854 |
Loads a pixmap from the \a len first bytes of the given binary \a |
|
855 |
data. Returns true if the pixmap was loaded successfully; |
|
856 |
otherwise returns false. |
|
857 |
||
858 |
The loader attempts to read the pixmap using the specified \a |
|
859 |
format. If the \a format is not specified (which is the default), |
|
860 |
the loader probes the file for a header to guess the file format. |
|
861 |
||
862 |
If the data needs to be modified to fit in a lower-resolution |
|
863 |
result (e.g. converting from 32-bit to 8-bit), use the \a flags to |
|
864 |
control the conversion. |
|
865 |
||
866 |
\sa load(), {QPixmap#Reading and Writing Image Files}{Reading and |
|
867 |
Writing Image Files} |
|
868 |
*/ |
|
869 |
||
870 |
bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) |
|
871 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
872 |
if (len == 0 || buf == 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
873 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
874 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
875 |
if (!data) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
876 |
data = QPixmapData::create(0, 0, QPixmapData::PixmapType); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
877 |
|
0 | 878 |
return data->fromData(buf, len, format, flags); |
879 |
} |
|
880 |
||
881 |
/*! |
|
882 |
\fn bool QPixmap::loadFromData(const QByteArray &data, const char *format, Qt::ImageConversionFlags flags) |
|
883 |
||
884 |
\overload |
|
885 |
||
886 |
Loads a pixmap from the binary \a data using the specified \a |
|
887 |
format and conversion \a flags. |
|
888 |
*/ |
|
889 |
||
890 |
||
891 |
/*! |
|
892 |
Saves the pixmap to the file with the given \a fileName using the |
|
893 |
specified image file \a format and \a quality factor. Returns true |
|
894 |
if successful; otherwise returns false. |
|
895 |
||
896 |
The \a quality factor must be in the range [0,100] or -1. Specify |
|
897 |
0 to obtain small compressed files, 100 for large uncompressed |
|
898 |
files, and -1 to use the default settings. |
|
899 |
||
900 |
If \a format is 0, an image format will be chosen from \a fileName's |
|
901 |
suffix. |
|
902 |
||
903 |
\sa {QPixmap#Reading and Writing Image Files}{Reading and Writing |
|
904 |
Image Files} |
|
905 |
*/ |
|
906 |
||
907 |
bool QPixmap::save(const QString &fileName, const char *format, int quality) const |
|
908 |
{ |
|
909 |
if (isNull()) |
|
910 |
return false; // nothing to save |
|
911 |
QImageWriter writer(fileName, format); |
|
912 |
return doImageIO(&writer, quality); |
|
913 |
} |
|
914 |
||
915 |
/*! |
|
916 |
\overload |
|
917 |
||
918 |
This function writes a QPixmap to the given \a device using the |
|
919 |
specified image file \a format and \a quality factor. This can be |
|
920 |
used, for example, to save a pixmap directly into a QByteArray: |
|
921 |
||
922 |
\snippet doc/src/snippets/image/image.cpp 1 |
|
923 |
*/ |
|
924 |
||
925 |
bool QPixmap::save(QIODevice* device, const char* format, int quality) const |
|
926 |
{ |
|
927 |
if (isNull()) |
|
928 |
return false; // nothing to save |
|
929 |
QImageWriter writer(device, format); |
|
930 |
return doImageIO(&writer, quality); |
|
931 |
} |
|
932 |
||
933 |
/*! \internal |
|
934 |
*/ |
|
935 |
bool QPixmap::doImageIO(QImageWriter *writer, int quality) const |
|
936 |
{ |
|
937 |
if (quality > 100 || quality < -1) |
|
938 |
qWarning("QPixmap::save: quality out of range [-1,100]"); |
|
939 |
if (quality >= 0) |
|
940 |
writer->setQuality(qMin(quality,100)); |
|
941 |
return writer->write(toImage()); |
|
942 |
} |
|
943 |
||
944 |
||
945 |
// The implementation (and documentation) of |
|
946 |
// QPixmap::fill(const QWidget *, const QPoint &) |
|
947 |
// is in qwidget.cpp |
|
948 |
||
949 |
/*! |
|
950 |
\fn void QPixmap::fill(const QWidget *widget, int x, int y) |
|
951 |
\overload |
|
952 |
||
953 |
Fills the pixmap with the \a widget's background color or pixmap. |
|
954 |
The given point, (\a x, \a y), defines an offset in widget |
|
955 |
coordinates to which the pixmap's top-left pixel will be mapped |
|
956 |
to. |
|
957 |
*/ |
|
958 |
||
959 |
/*! |
|
960 |
Fills the pixmap with the given \a color. |
|
961 |
||
962 |
The effect of this function is undefined when the pixmap is |
|
963 |
being painted on. |
|
964 |
||
965 |
\sa {QPixmap#Pixmap Transformations}{Pixmap Transformations} |
|
966 |
*/ |
|
967 |
||
968 |
void QPixmap::fill(const QColor &color) |
|
969 |
{ |
|
970 |
if (isNull()) |
|
971 |
return; |
|
972 |
||
973 |
// Some people are probably already calling fill while a painter is active, so to not break |
|
974 |
// their programs, only print a warning and return when the fill operation could cause a crash. |
|
975 |
if (paintingActive() && (color.alpha() != 255) && !hasAlphaChannel()) { |
|
976 |
qWarning("QPixmap::fill: Cannot fill while pixmap is being painted on"); |
|
977 |
return; |
|
978 |
} |
|
979 |
||
980 |
if (data->ref == 1) { |
|
981 |
// detach() will also remove this pixmap from caches, so |
|
982 |
// it has to be called even when ref == 1. |
|
983 |
detach(); |
|
984 |
} else { |
|
985 |
// Don't bother to make a copy of the data object, since |
|
986 |
// it will be filled with new pixel data anyway. |
|
987 |
QPixmapData *d = data->createCompatiblePixmapData(); |
|
988 |
d->resize(data->width(), data->height()); |
|
989 |
data = d; |
|
990 |
} |
|
991 |
data->fill(color); |
|
992 |
} |
|
993 |
||
994 |
/*! \obsolete |
|
995 |
Returns a number that identifies the contents of this QPixmap |
|
996 |
object. Distinct QPixmap objects can only have the same serial |
|
997 |
number if they refer to the same contents (but they don't have |
|
998 |
to). |
|
999 |
||
1000 |
Use cacheKey() instead. |
|
1001 |
||
1002 |
\warning The serial number doesn't necessarily change when |
|
1003 |
the pixmap is altered. This means that it may be dangerous to use |
|
1004 |
it as a cache key. For caching pixmaps, we recommend using the |
|
1005 |
QPixmapCache class whenever possible. |
|
1006 |
*/ |
|
1007 |
int QPixmap::serialNumber() const |
|
1008 |
{ |
|
1009 |
if (isNull()) |
|
1010 |
return 0; |
|
1011 |
return data->serialNumber(); |
|
1012 |
} |
|
1013 |
||
1014 |
/*! |
|
1015 |
Returns a number that identifies this QPixmap. Distinct QPixmap |
|
1016 |
objects can only have the same cache key if they refer to the same |
|
1017 |
contents. |
|
1018 |
||
1019 |
The cacheKey() will change when the pixmap is altered. |
|
1020 |
*/ |
|
1021 |
qint64 QPixmap::cacheKey() const |
|
1022 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1023 |
if (isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1024 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1025 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1026 |
Q_ASSERT(data); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1027 |
return data->cacheKey(); |
0 | 1028 |
} |
1029 |
||
1030 |
static void sendResizeEvents(QWidget *target) |
|
1031 |
{ |
|
1032 |
QResizeEvent e(target->size(), QSize()); |
|
1033 |
QApplication::sendEvent(target, &e); |
|
1034 |
||
1035 |
const QObjectList children = target->children(); |
|
1036 |
for (int i = 0; i < children.size(); ++i) { |
|
1037 |
QWidget *child = static_cast<QWidget*>(children.at(i)); |
|
1038 |
if (child->isWidgetType() && !child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent)) |
|
1039 |
sendResizeEvents(child); |
|
1040 |
} |
|
1041 |
} |
|
1042 |
||
1043 |
/*! |
|
1044 |
\fn QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rectangle) |
|
1045 |
||
1046 |
Creates a pixmap and paints the given \a widget, restricted by the |
|
1047 |
given \a rectangle, in it. If the \a widget has any children, then |
|
1048 |
they are also painted in the appropriate positions. |
|
1049 |
||
1050 |
If no rectangle is specified (the default) the entire widget is |
|
1051 |
painted. |
|
1052 |
||
1053 |
If \a widget is 0, the specified rectangle doesn't overlap the |
|
1054 |
widget's rectangle, or an error occurs, the function will return a |
|
1055 |
null QPixmap. If the rectangle is a superset of the given \a |
|
1056 |
widget, the areas outside the \a widget are covered with the |
|
1057 |
widget's background. |
|
1058 |
||
1059 |
This function actually asks \a widget to paint itself (and its |
|
1060 |
children to paint themselves) by calling paintEvent() with painter |
|
1061 |
redirection turned on. But QPixmap also provides the grabWindow() |
|
1062 |
function which is a bit faster by grabbing pixels directly off the |
|
1063 |
screen. In addition, if there are overlaying windows, |
|
1064 |
grabWindow(), unlike grabWidget(), will see them. |
|
1065 |
||
1066 |
\warning Do not grab a widget from its QWidget::paintEvent(). |
|
1067 |
However, it is safe to grab a widget from another widget's |
|
1068 |
\l {QWidget::}{paintEvent()}. |
|
1069 |
||
1070 |
\sa grabWindow() |
|
1071 |
*/ |
|
1072 |
||
1073 |
QPixmap QPixmap::grabWidget(QWidget * widget, const QRect &rect) |
|
1074 |
{ |
|
1075 |
if (!widget) |
|
1076 |
return QPixmap(); |
|
1077 |
||
1078 |
if (widget->testAttribute(Qt::WA_PendingResizeEvent) || !widget->testAttribute(Qt::WA_WState_Created)) |
|
1079 |
sendResizeEvents(widget); |
|
1080 |
||
1081 |
QRect r(rect); |
|
1082 |
if (r.width() < 0) |
|
1083 |
r.setWidth(widget->width() - rect.x()); |
|
1084 |
if (r.height() < 0) |
|
1085 |
r.setHeight(widget->height() - rect.y()); |
|
1086 |
||
1087 |
if (!r.intersects(widget->rect())) |
|
1088 |
return QPixmap(); |
|
1089 |
||
1090 |
QPixmap res(r.size()); |
|
1091 |
widget->render(&res, QPoint(), r, |
|
1092 |
QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); |
|
1093 |
return res; |
|
1094 |
} |
|
1095 |
||
1096 |
/*! |
|
1097 |
\fn QPixmap QPixmap::grabWidget(QWidget *widget, int x, int y, int |
|
1098 |
width, int height) |
|
1099 |
||
1100 |
\overload |
|
1101 |
||
1102 |
Creates a pixmap and paints the given \a widget, restricted by |
|
1103 |
QRect(\a x, \a y, \a width, \a height), in it. |
|
1104 |
||
1105 |
\warning Do not grab a widget from its QWidget::paintEvent(). |
|
1106 |
However, it is safe to grab a widget from another widget's |
|
1107 |
\l {QWidget::}{paintEvent()}. |
|
1108 |
*/ |
|
1109 |
||
1110 |
||
1111 |
/*! |
|
1112 |
\since 4.5 |
|
1113 |
||
1114 |
\enum QPixmap::ShareMode |
|
1115 |
||
1116 |
This enum type defines the share modes that are available when |
|
1117 |
creating a QPixmap object from a raw X11 Pixmap handle. |
|
1118 |
||
1119 |
\value ImplicitlyShared This mode will cause the QPixmap object to |
|
1120 |
create a copy of the internal data before it is modified, thus |
|
1121 |
keeping the original X11 pixmap intact. |
|
1122 |
||
1123 |
\value ExplicitlyShared In this mode, the pixmap data will \e not be |
|
1124 |
copied before it is modified, which in effect will change the |
|
1125 |
original X11 pixmap. |
|
1126 |
||
1127 |
\warning This enum is only used for X11 specific functions; using |
|
1128 |
it is non-portable. |
|
1129 |
||
1130 |
\sa QPixmap::fromX11Pixmap() |
|
1131 |
*/ |
|
1132 |
||
1133 |
/*! |
|
1134 |
\since 4.5 |
|
1135 |
||
1136 |
\fn QPixmap QPixmap::fromX11Pixmap(Qt::HANDLE pixmap, QPixmap::ShareMode mode) |
|
1137 |
||
1138 |
Creates a QPixmap from the native X11 Pixmap handle \a pixmap, |
|
1139 |
using \a mode as the share mode. The default share mode is |
|
1140 |
QPixmap::ImplicitlyShared, which means that a copy of the pixmap is |
|
1141 |
made if someone tries to modify it by e.g. drawing onto it. |
|
1142 |
||
1143 |
QPixmap does \e not take ownership of the \a pixmap handle, and |
|
1144 |
have to be deleted by the user. |
|
1145 |
||
1146 |
\warning This function is X11 specific; using it is non-portable. |
|
1147 |
||
1148 |
\sa QPixmap::ShareMode |
|
1149 |
*/ |
|
1150 |
||
1151 |
||
1152 |
#if defined(Q_WS_X11) || defined(Q_WS_QWS) |
|
1153 |
||
1154 |
/*! |
|
1155 |
Returns the pixmap's handle to the device context. |
|
1156 |
||
1157 |
Note that, since QPixmap make use of \l {Implicit Data |
|
1158 |
Sharing}{implicit data sharing}, the detach() function must be |
|
1159 |
called explicitly to ensure that only \e this pixmap's data is |
|
1160 |
modified if the pixmap data is shared. |
|
1161 |
||
1162 |
\warning This function is X11 specific; using it is non-portable. |
|
1163 |
||
1164 |
\sa detach() |
|
1165 |
*/ |
|
1166 |
||
1167 |
Qt::HANDLE QPixmap::handle() const |
|
1168 |
{ |
|
1169 |
#if defined(Q_WS_X11) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1170 |
if (data && data->classId() == QPixmapData::X11Class) |
0 | 1171 |
return static_cast<const QX11PixmapData*>(data.constData())->handle(); |
1172 |
#endif |
|
1173 |
return 0; |
|
1174 |
} |
|
1175 |
#endif |
|
1176 |
||
1177 |
||
1178 |
#ifdef QT3_SUPPORT |
|
1179 |
static Qt::ImageConversionFlags colorModeToFlags(QPixmap::ColorMode mode) |
|
1180 |
{ |
|
1181 |
Qt::ImageConversionFlags flags = Qt::AutoColor; |
|
1182 |
switch (mode) { |
|
1183 |
case QPixmap::Color: |
|
1184 |
flags |= Qt::ColorOnly; |
|
1185 |
break; |
|
1186 |
case QPixmap::Mono: |
|
1187 |
flags |= Qt::MonoOnly; |
|
1188 |
break; |
|
1189 |
default: |
|
1190 |
break;// Nothing. |
|
1191 |
} |
|
1192 |
return flags; |
|
1193 |
} |
|
1194 |
||
1195 |
/*! |
|
1196 |
Use the constructor that takes a Qt::ImageConversionFlag instead. |
|
1197 |
*/ |
|
1198 |
||
1199 |
QPixmap::QPixmap(const QString& fileName, const char *format, ColorMode mode) |
|
1200 |
: QPaintDevice() |
|
1201 |
{ |
|
1202 |
init(0, 0, QPixmapData::PixmapType); |
|
1203 |
if (!qt_pixmap_thread_test()) |
|
1204 |
return; |
|
1205 |
||
1206 |
load(fileName, format, colorModeToFlags(mode)); |
|
1207 |
} |
|
1208 |
||
1209 |
/*! |
|
1210 |
Constructs a pixmap from the QImage \a image. |
|
1211 |
||
1212 |
Use the static fromImage() function instead. |
|
1213 |
*/ |
|
1214 |
QPixmap::QPixmap(const QImage& image) |
|
1215 |
: QPaintDevice() |
|
1216 |
{ |
|
1217 |
init(0, 0, QPixmapData::PixmapType); |
|
1218 |
if (!qt_pixmap_thread_test()) |
|
1219 |
return; |
|
1220 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1221 |
if (data && data->pixelType() == QPixmapData::BitmapType) |
0 | 1222 |
*this = QBitmap::fromImage(image); |
1223 |
else |
|
1224 |
*this = fromImage(image); |
|
1225 |
} |
|
1226 |
||
1227 |
/*! |
|
1228 |
\overload |
|
1229 |
||
1230 |
Converts the given \a image to a pixmap that is assigned to this |
|
1231 |
pixmap. |
|
1232 |
||
1233 |
Use the static fromImage() function instead. |
|
1234 |
*/ |
|
1235 |
||
1236 |
QPixmap &QPixmap::operator=(const QImage &image) |
|
1237 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1238 |
if (data && data->pixelType() == QPixmapData::BitmapType) |
0 | 1239 |
*this = QBitmap::fromImage(image); |
1240 |
else |
|
1241 |
*this = fromImage(image); |
|
1242 |
return *this; |
|
1243 |
} |
|
1244 |
||
1245 |
/*! |
|
1246 |
Use the load() function that takes a Qt::ImageConversionFlag instead. |
|
1247 |
*/ |
|
1248 |
||
1249 |
bool QPixmap::load(const QString &fileName, const char *format, ColorMode mode) |
|
1250 |
{ |
|
1251 |
return load(fileName, format, colorModeToFlags(mode)); |
|
1252 |
} |
|
1253 |
||
1254 |
/*! |
|
1255 |
Use the loadFromData() function that takes a Qt::ImageConversionFlag instead. |
|
1256 |
*/ |
|
1257 |
||
1258 |
bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, ColorMode mode) |
|
1259 |
{ |
|
1260 |
return loadFromData(buf, len, format, colorModeToFlags(mode)); |
|
1261 |
} |
|
1262 |
||
1263 |
/*! |
|
1264 |
Use the static fromImage() function instead. |
|
1265 |
*/ |
|
1266 |
bool QPixmap::convertFromImage(const QImage &image, ColorMode mode) |
|
1267 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1268 |
if (data && data->pixelType() == QPixmapData::BitmapType) |
0 | 1269 |
*this = QBitmap::fromImage(image, colorModeToFlags(mode)); |
1270 |
else |
|
1271 |
*this = fromImage(image, colorModeToFlags(mode)); |
|
1272 |
return !isNull(); |
|
1273 |
} |
|
1274 |
||
1275 |
#endif |
|
1276 |
||
1277 |
/***************************************************************************** |
|
1278 |
QPixmap stream functions |
|
1279 |
*****************************************************************************/ |
|
1280 |
#if !defined(QT_NO_DATASTREAM) |
|
1281 |
/*! |
|
1282 |
\relates QPixmap |
|
1283 |
||
1284 |
Writes the given \a pixmap to the given \a stream as a PNG |
|
1285 |
image. Note that writing the stream to a file will not produce a |
|
1286 |
valid image file. |
|
1287 |
||
1288 |
\sa QPixmap::save(), {Format of the QDataStream Operators} |
|
1289 |
*/ |
|
1290 |
||
1291 |
QDataStream &operator<<(QDataStream &stream, const QPixmap &pixmap) |
|
1292 |
{ |
|
1293 |
return stream << pixmap.toImage(); |
|
1294 |
} |
|
1295 |
||
1296 |
/*! |
|
1297 |
\relates QPixmap |
|
1298 |
||
1299 |
Reads an image from the given \a stream into the given \a pixmap. |
|
1300 |
||
1301 |
\sa QPixmap::load(), {Format of the QDataStream Operators} |
|
1302 |
*/ |
|
1303 |
||
1304 |
QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap) |
|
1305 |
{ |
|
1306 |
QImage image; |
|
1307 |
stream >> image; |
|
1308 |
||
1309 |
if (image.isNull()) { |
|
1310 |
pixmap = QPixmap(); |
|
1311 |
} else if (image.depth() == 1) { |
|
1312 |
pixmap = QBitmap::fromImage(image); |
|
1313 |
} else { |
|
1314 |
pixmap = QPixmap::fromImage(image); |
|
1315 |
} |
|
1316 |
return stream; |
|
1317 |
} |
|
1318 |
||
1319 |
#endif // QT_NO_DATASTREAM |
|
1320 |
||
1321 |
#ifdef QT3_SUPPORT |
|
1322 |
Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy, |
|
1323 |
const QPixmap *src, int sx, int sy, int sw, int sh) |
|
1324 |
{ |
|
1325 |
Q_ASSERT_X(dst, "::copyBlt", "Destination pixmap must be non-null"); |
|
1326 |
Q_ASSERT_X(src, "::copyBlt", "Source pixmap must be non-null"); |
|
1327 |
||
1328 |
if (src->hasAlphaChannel()) { |
|
1329 |
if (dst->paintEngine()->hasFeature(QPaintEngine::PorterDuff)) { |
|
1330 |
QPainter p(dst); |
|
1331 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
1332 |
p.drawPixmap(dx, dy, *src, sx, sy, sw, sh); |
|
1333 |
} else { |
|
1334 |
QImage image = dst->toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); |
|
1335 |
QPainter p(&image); |
|
1336 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
1337 |
p.drawPixmap(dx, dy, *src, sx, sy, sw, sh); |
|
1338 |
p.end(); |
|
1339 |
*dst = QPixmap::fromImage(image); |
|
1340 |
} |
|
1341 |
} else { |
|
1342 |
QPainter p(dst); |
|
1343 |
p.drawPixmap(dx, dy, *src, sx, sy, sw, sh); |
|
1344 |
} |
|
1345 |
||
1346 |
} |
|
1347 |
#endif |
|
1348 |
||
1349 |
/*! |
|
1350 |
\internal |
|
1351 |
*/ |
|
1352 |
||
1353 |
bool QPixmap::isDetached() const |
|
1354 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1355 |
return data && data->ref == 1; |
0 | 1356 |
} |
1357 |
||
1358 |
/*! \internal |
|
1359 |
### Qt5 - remove me. |
|
1360 |
*/ |
|
1361 |
void QPixmap::deref() |
|
1362 |
{ |
|
1363 |
Q_ASSERT_X(false, "QPixmap::deref()", "Do not call this function anymore!"); |
|
1364 |
} |
|
1365 |
||
1366 |
/*! |
|
1367 |
\fn QImage QPixmap::convertToImage() const |
|
1368 |
||
1369 |
Use the toImage() function instead. |
|
1370 |
*/ |
|
1371 |
||
1372 |
/*! |
|
1373 |
\fn bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags) |
|
1374 |
||
1375 |
Use the static fromImage() function instead. |
|
1376 |
*/ |
|
1377 |
||
1378 |
/*! |
|
1379 |
\fn QPixmap QPixmap::xForm(const QMatrix &matrix) const |
|
1380 |
||
1381 |
Use transformed() instead. |
|
1382 |
*/ |
|
1383 |
||
1384 |
/*! |
|
1385 |
\fn QPixmap QPixmap::scaled(int width, int height, |
|
1386 |
Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode |
|
1387 |
transformMode) const |
|
1388 |
||
1389 |
\overload |
|
1390 |
||
1391 |
Returns a copy of the pixmap scaled to a rectangle with the given |
|
1392 |
\a width and \a height according to the given \a aspectRatioMode and |
|
1393 |
\a transformMode. |
|
1394 |
||
1395 |
If either the \a width or the \a height is zero or negative, this |
|
1396 |
function returns a null pixmap. |
|
1397 |
*/ |
|
1398 |
||
1399 |
/*! |
|
1400 |
\fn QPixmap QPixmap::scaled(const QSize &size, Qt::AspectRatioMode |
|
1401 |
aspectRatioMode, Qt::TransformationMode transformMode) const |
|
1402 |
||
1403 |
Scales the pixmap to the given \a size, using the aspect ratio and |
|
1404 |
transformation modes specified by \a aspectRatioMode and \a |
|
1405 |
transformMode. |
|
1406 |
||
1407 |
\image qimage-scaling.png |
|
1408 |
||
1409 |
\list |
|
1410 |
\i If \a aspectRatioMode is Qt::IgnoreAspectRatio, the pixmap |
|
1411 |
is scaled to \a size. |
|
1412 |
\i If \a aspectRatioMode is Qt::KeepAspectRatio, the pixmap is |
|
1413 |
scaled to a rectangle as large as possible inside \a size, preserving the aspect ratio. |
|
1414 |
\i If \a aspectRatioMode is Qt::KeepAspectRatioByExpanding, |
|
1415 |
the pixmap is scaled to a rectangle as small as possible |
|
1416 |
outside \a size, preserving the aspect ratio. |
|
1417 |
\endlist |
|
1418 |
||
1419 |
If the given \a size is empty, this function returns a null |
|
1420 |
pixmap. |
|
1421 |
||
1422 |
||
1423 |
In some cases it can be more beneficial to draw the pixmap to a |
|
1424 |
painter with a scale set rather than scaling the pixmap. This is |
|
1425 |
the case when the painter is for instance based on OpenGL or when |
|
1426 |
the scale factor changes rapidly. |
|
1427 |
||
1428 |
\sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap |
|
1429 |
Transformations} |
|
1430 |
||
1431 |
*/ |
|
1432 |
QPixmap QPixmap::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const |
|
1433 |
{ |
|
1434 |
if (isNull()) { |
|
1435 |
qWarning("QPixmap::scaled: Pixmap is a null pixmap"); |
|
1436 |
return QPixmap(); |
|
1437 |
} |
|
1438 |
if (s.isEmpty()) |
|
1439 |
return QPixmap(); |
|
1440 |
||
1441 |
QSize newSize = size(); |
|
1442 |
newSize.scale(s, aspectMode); |
|
1443 |
if (newSize == size()) |
|
1444 |
return *this; |
|
1445 |
||
1446 |
QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), |
|
1447 |
(qreal)newSize.height() / height()); |
|
1448 |
QPixmap pix = transformed(wm, mode); |
|
1449 |
return pix; |
|
1450 |
} |
|
1451 |
||
1452 |
/*! |
|
1453 |
\fn QPixmap QPixmap::scaledToWidth(int width, Qt::TransformationMode |
|
1454 |
mode) const |
|
1455 |
||
1456 |
Returns a scaled copy of the image. The returned image is scaled |
|
1457 |
to the given \a width using the specified transformation \a mode. |
|
1458 |
The height of the pixmap is automatically calculated so that the |
|
1459 |
aspect ratio of the pixmap is preserved. |
|
1460 |
||
1461 |
If \a width is 0 or negative, a null pixmap is returned. |
|
1462 |
||
1463 |
\sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap |
|
1464 |
Transformations} |
|
1465 |
*/ |
|
1466 |
QPixmap QPixmap::scaledToWidth(int w, Qt::TransformationMode mode) const |
|
1467 |
{ |
|
1468 |
if (isNull()) { |
|
1469 |
qWarning("QPixmap::scaleWidth: Pixmap is a null pixmap"); |
|
1470 |
return copy(); |
|
1471 |
} |
|
1472 |
if (w <= 0) |
|
1473 |
return QPixmap(); |
|
1474 |
||
1475 |
qreal factor = (qreal) w / width(); |
|
1476 |
QTransform wm = QTransform::fromScale(factor, factor); |
|
1477 |
return transformed(wm, mode); |
|
1478 |
} |
|
1479 |
||
1480 |
/*! |
|
1481 |
\fn QPixmap QPixmap::scaledToHeight(int height, |
|
1482 |
Qt::TransformationMode mode) const |
|
1483 |
||
1484 |
Returns a scaled copy of the image. The returned image is scaled |
|
1485 |
to the given \a height using the specified transformation \a mode. |
|
1486 |
The width of the pixmap is automatically calculated so that the |
|
1487 |
aspect ratio of the pixmap is preserved. |
|
1488 |
||
1489 |
If \a height is 0 or negative, a null pixmap is returned. |
|
1490 |
||
1491 |
\sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap |
|
1492 |
Transformations} |
|
1493 |
*/ |
|
1494 |
QPixmap QPixmap::scaledToHeight(int h, Qt::TransformationMode mode) const |
|
1495 |
{ |
|
1496 |
if (isNull()) { |
|
1497 |
qWarning("QPixmap::scaleHeight: Pixmap is a null pixmap"); |
|
1498 |
return copy(); |
|
1499 |
} |
|
1500 |
if (h <= 0) |
|
1501 |
return QPixmap(); |
|
1502 |
||
1503 |
qreal factor = (qreal) h / height(); |
|
1504 |
QTransform wm = QTransform::fromScale(factor, factor); |
|
1505 |
return transformed(wm, mode); |
|
1506 |
} |
|
1507 |
||
1508 |
/*! |
|
1509 |
Returns a copy of the pixmap that is transformed using the given |
|
1510 |
transformation \a transform and transformation \a mode. The original |
|
1511 |
pixmap is not changed. |
|
1512 |
||
1513 |
The transformation \a transform is internally adjusted to compensate |
|
1514 |
for unwanted translation; i.e. the pixmap produced is the smallest |
|
1515 |
pixmap that contains all the transformed points of the original |
|
1516 |
pixmap. Use the trueMatrix() function to retrieve the actual |
|
1517 |
matrix used for transforming the pixmap. |
|
1518 |
||
1519 |
This function is slow because it involves transformation to a |
|
1520 |
QImage, non-trivial computations and a transformation back to a |
|
1521 |
QPixmap. |
|
1522 |
||
1523 |
\sa trueMatrix(), {QPixmap#Pixmap Transformations}{Pixmap |
|
1524 |
Transformations} |
|
1525 |
*/ |
|
1526 |
QPixmap QPixmap::transformed(const QTransform &transform, |
|
1527 |
Qt::TransformationMode mode) const |
|
1528 |
{ |
|
1529 |
if (isNull() || transform.type() <= QTransform::TxTranslate) |
|
1530 |
return *this; |
|
1531 |
||
1532 |
return data->transformed(transform, mode); |
|
1533 |
} |
|
1534 |
||
1535 |
/*! |
|
1536 |
\overload |
|
1537 |
||
1538 |
This convenience function loads the \a matrix into a |
|
1539 |
QTransform and calls the overloaded function. |
|
1540 |
*/ |
|
1541 |
QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) const |
|
1542 |
{ |
|
1543 |
return transformed(QTransform(matrix), mode); |
|
1544 |
} |
|
1545 |
||
1546 |
||
1547 |
||
1548 |
||
1549 |
||
1550 |
||
1551 |
||
1552 |
||
1553 |
/*! |
|
1554 |
\class QPixmap |
|
1555 |
||
1556 |
\brief The QPixmap class is an off-screen image representation |
|
1557 |
that can be used as a paint device. |
|
1558 |
||
1559 |
\ingroup painting |
|
1560 |
\ingroup shared |
|
1561 |
||
1562 |
||
1563 |
Qt provides four classes for handling image data: QImage, QPixmap, |
|
1564 |
QBitmap and QPicture. QImage is designed and optimized for I/O, |
|
1565 |
and for direct pixel access and manipulation, while QPixmap is |
|
1566 |
designed and optimized for showing images on screen. QBitmap is |
|
1567 |
only a convenience class that inherits QPixmap, ensuring a depth |
|
1568 |
of 1. The isQBitmap() function returns true if a QPixmap object is |
|
1569 |
really a bitmap, otherwise returns false. Finally, the QPicture class |
|
1570 |
is a paint device that records and replays QPainter commands. |
|
1571 |
||
1572 |
A QPixmap can easily be displayed on the screen using QLabel or |
|
1573 |
one of QAbstractButton's subclasses (such as QPushButton and |
|
1574 |
QToolButton). QLabel has a pixmap property, whereas |
|
1575 |
QAbstractButton has an icon property. |
|
1576 |
||
1577 |
In addition to the ordinary constructors, a QPixmap can be |
|
1578 |
constructed using the static grabWidget() and grabWindow() |
|
1579 |
functions which creates a QPixmap and paints the given widget, or |
|
1580 |
window, into it. |
|
1581 |
||
1582 |
QPixmap objects can be passed around by value since the QPixmap |
|
1583 |
class uses implicit data sharing. For more information, see the \l |
|
1584 |
{Implicit Data Sharing} documentation. QPixmap objects can also be |
|
1585 |
streamed. |
|
1586 |
||
1587 |
Depending on the system, QPixmap is stored using a RGB32 or a |
|
1588 |
premultiplied alpha format. If the image has an alpha channel, and |
|
1589 |
if the system allows, the preferred format is premultiplied alpha. |
|
1590 |
Note also that QPixmap, unlike QImage, may be hardware dependent. |
|
1591 |
On X11, Mac and Symbian, a QPixmap is stored on the server side while |
|
1592 |
a QImage is stored on the client side (on Windows, these two classes |
|
1593 |
have an equivalent internal representation, i.e. both QImage and |
|
1594 |
QPixmap are stored on the client side and don't use any GDI |
|
1595 |
resources). |
|
1596 |
||
1597 |
Note that the pixel data in a pixmap is internal and is managed by |
|
1598 |
the underlying window system. Because QPixmap is a QPaintDevice |
|
1599 |
subclass, QPainter can be used to draw directly onto pixmaps. |
|
1600 |
Pixels can only be accessed through QPainter functions or by |
|
1601 |
converting the QPixmap to a QImage. However, the fill() function |
|
1602 |
is available for initializing the entire pixmap with a given color. |
|
1603 |
||
1604 |
There are functions to convert between QImage and |
|
1605 |
QPixmap. Typically, the QImage class is used to load an image |
|
1606 |
file, optionally manipulating the image data, before the QImage |
|
1607 |
object is converted into a QPixmap to be shown on |
|
1608 |
screen. Alternatively, if no manipulation is desired, the image |
|
1609 |
file can be loaded directly into a QPixmap. On Windows, the |
|
1610 |
QPixmap class also supports conversion between \c HBITMAP and |
|
1611 |
QPixmap. On Symbian, the QPixmap class also supports conversion |
|
1612 |
between CFbsBitmap and QPixmap. |
|
1613 |
||
1614 |
QPixmap provides a collection of functions that can be used to |
|
1615 |
obtain a variety of information about the pixmap. In addition, |
|
1616 |
there are several functions that enables transformation of the |
|
1617 |
pixmap. |
|
1618 |
||
1619 |
\tableofcontents |
|
1620 |
||
1621 |
\section1 Reading and Writing Image Files |
|
1622 |
||
1623 |
QPixmap provides several ways of reading an image file: The file |
|
1624 |
can be loaded when constructing the QPixmap object, or by using |
|
1625 |
the load() or loadFromData() functions later on. When loading an |
|
1626 |
image, the file name can either refer to an actual file on disk or |
|
1627 |
to one of the application's embedded resources. See \l{The Qt |
|
1628 |
Resource System} overview for details on how to embed images and |
|
1629 |
other resource files in the application's executable. |
|
1630 |
||
1631 |
Simply call the save() function to save a QPixmap object. |
|
1632 |
||
1633 |
The complete list of supported file formats are available through |
|
1634 |
the QImageReader::supportedImageFormats() and |
|
1635 |
QImageWriter::supportedImageFormats() functions. New file formats |
|
1636 |
can be added as plugins. By default, Qt supports the following |
|
1637 |
formats: |
|
1638 |
||
1639 |
\table |
|
1640 |
\header \o Format \o Description \o Qt's support |
|
1641 |
\row \o BMP \o Windows Bitmap \o Read/write |
|
1642 |
\row \o GIF \o Graphic Interchange Format (optional) \o Read |
|
1643 |
\row \o JPG \o Joint Photographic Experts Group \o Read/write |
|
1644 |
\row \o JPEG \o Joint Photographic Experts Group \o Read/write |
|
1645 |
\row \o PNG \o Portable Network Graphics \o Read/write |
|
1646 |
\row \o PBM \o Portable Bitmap \o Read |
|
1647 |
\row \o PGM \o Portable Graymap \o Read |
|
1648 |
\row \o PPM \o Portable Pixmap \o Read/write |
|
1649 |
\row \o XBM \o X11 Bitmap \o Read/write |
|
1650 |
\row \o XPM \o X11 Pixmap \o Read/write |
|
1651 |
\endtable |
|
1652 |
||
1653 |
\section1 Pixmap Information |
|
1654 |
||
1655 |
QPixmap provides a collection of functions that can be used to |
|
1656 |
obtain a variety of information about the pixmap: |
|
1657 |
||
1658 |
\table |
|
1659 |
\header |
|
1660 |
\o \o Available Functions |
|
1661 |
\row |
|
1662 |
\o Geometry |
|
1663 |
\o |
|
1664 |
The size(), width() and height() functions provide information |
|
1665 |
about the pixmap's size. The rect() function returns the image's |
|
1666 |
enclosing rectangle. |
|
1667 |
||
1668 |
\row |
|
1669 |
\o Alpha component |
|
1670 |
\o |
|
1671 |
||
1672 |
The hasAlphaChannel() returns true if the pixmap has a format that |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1673 |
respects the alpha channel, otherwise returns false. The hasAlpha(), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1674 |
setMask() and mask() functions are legacy and should not be used. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1675 |
They are potentially very slow. |
0 | 1676 |
|
1677 |
The createHeuristicMask() function creates and returns a 1-bpp |
|
1678 |
heuristic mask (i.e. a QBitmap) for this pixmap. It works by |
|
1679 |
selecting a color from one of the corners and then chipping away |
|
1680 |
pixels of that color, starting at all the edges. The |
|
1681 |
createMaskFromColor() function creates and returns a mask (i.e. a |
|
1682 |
QBitmap) for the pixmap based on a given color. |
|
1683 |
||
1684 |
\row |
|
1685 |
\o Low-level information |
|
1686 |
\o |
|
1687 |
||
1688 |
The depth() function returns the depth of the pixmap. The |
|
1689 |
defaultDepth() function returns the default depth, i.e. the depth |
|
1690 |
used by the application on the given screen. |
|
1691 |
||
1692 |
The cacheKey() function returns a number that uniquely |
|
1693 |
identifies the contents of the QPixmap object. |
|
1694 |
||
1695 |
The x11Info() function returns information about the configuration |
|
1696 |
of the X display used by the screen to which the pixmap currently |
|
1697 |
belongs. The x11PictureHandle() function returns the X11 Picture |
|
1698 |
handle of the pixmap for XRender support. Note that the two latter |
|
1699 |
functions are only available on x11. |
|
1700 |
||
1701 |
\endtable |
|
1702 |
||
1703 |
\section1 Pixmap Conversion |
|
1704 |
||
1705 |
A QPixmap object can be converted into a QImage using the |
|
1706 |
toImage() function. Likewise, a QImage can be converted into a |
|
1707 |
QPixmap using the fromImage(). If this is too expensive an |
|
1708 |
operation, you can use QBitmap::fromImage() instead. |
|
1709 |
||
1710 |
In addition, on Windows, the QPixmap class supports conversion to |
|
1711 |
and from HBITMAP: the toWinHBITMAP() function creates a HBITMAP |
|
1712 |
equivalent to the QPixmap, based on the given HBitmapFormat, and |
|
1713 |
returns the HBITMAP handle. The fromWinHBITMAP() function returns |
|
1714 |
a QPixmap that is equivalent to the given bitmap which has the |
|
1715 |
specified format. The QPixmap class also supports conversion to |
|
1716 |
and from HICON: the toWinHICON() function creates a HICON equivalent |
|
1717 |
to the QPixmap, and returns the HICON handle. The fromWinHICON() |
|
1718 |
function returns a QPixmap that is equivalent to the given icon. |
|
1719 |
||
1720 |
In addition, on Symbian, the QPixmap class supports conversion to |
|
1721 |
and from CFbsBitmap: the toSymbianCFbsBitmap() function creates |
|
1722 |
CFbsBitmap equivalent to the QPixmap, based on given mode and returns |
|
1723 |
a CFbsBitmap object. The fromSymbianCFbsBitmap() function returns a |
|
1724 |
QPixmap that is equivalent to the given bitmap and given mode. |
|
1725 |
||
1726 |
\section1 Pixmap Transformations |
|
1727 |
||
1728 |
QPixmap supports a number of functions for creating a new pixmap |
|
1729 |
that is a transformed version of the original: |
|
1730 |
||
1731 |
The scaled(), scaledToWidth() and scaledToHeight() functions |
|
1732 |
return scaled copies of the pixmap, while the copy() function |
|
1733 |
creates a QPixmap that is a plain copy of the original one. |
|
1734 |
||
1735 |
The transformed() function returns a copy of the pixmap that is |
|
1736 |
transformed with the given transformation matrix and |
|
1737 |
transformation mode: Internally, the transformation matrix is |
|
1738 |
adjusted to compensate for unwanted translation, |
|
1739 |
i.e. transformed() returns the smallest pixmap containing all |
|
1740 |
transformed points of the original pixmap. The static trueMatrix() |
|
1741 |
function returns the actual matrix used for transforming the |
|
1742 |
pixmap. |
|
1743 |
||
1744 |
\sa QBitmap, QImage, QImageReader, QImageWriter |
|
1745 |
*/ |
|
1746 |
||
1747 |
||
1748 |
/*! |
|
1749 |
\typedef QPixmap::DataPtr |
|
1750 |
\internal |
|
1751 |
*/ |
|
1752 |
||
1753 |
/*! |
|
1754 |
\fn DataPtr &QPixmap::data_ptr() |
|
1755 |
\internal |
|
1756 |
*/ |
|
1757 |
||
1758 |
/*! |
|
1759 |
Returns true if this pixmap has an alpha channel, \e or has a |
|
1760 |
mask, otherwise returns false. |
|
1761 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1762 |
\warning This is potentially an expensive operation. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1763 |
|
0 | 1764 |
\sa hasAlphaChannel(), mask() |
1765 |
*/ |
|
1766 |
bool QPixmap::hasAlpha() const |
|
1767 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1768 |
return data && (data->hasAlphaChannel() || !data->mask().isNull()); |
0 | 1769 |
} |
1770 |
||
1771 |
/*! |
|
1772 |
Returns true if the pixmap has a format that respects the alpha |
|
1773 |
channel, otherwise returns false. |
|
1774 |
||
1775 |
\sa hasAlpha() |
|
1776 |
*/ |
|
1777 |
bool QPixmap::hasAlphaChannel() const |
|
1778 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1779 |
return data && data->hasAlphaChannel(); |
0 | 1780 |
} |
1781 |
||
1782 |
/*! |
|
1783 |
\internal |
|
1784 |
*/ |
|
1785 |
int QPixmap::metric(PaintDeviceMetric metric) const |
|
1786 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1787 |
return data ? data->metric(metric) : 0; |
0 | 1788 |
} |
1789 |
||
1790 |
/*! |
|
1791 |
\fn void QPixmap::setAlphaChannel(const QPixmap &alphaChannel) |
|
1792 |
\obsolete |
|
1793 |
||
1794 |
Sets the alpha channel of this pixmap to the given \a alphaChannel |
|
1795 |
by converting the \a alphaChannel into 32 bit and using the |
|
1796 |
intensity of the RGB pixel values. |
|
1797 |
||
1798 |
The effect of this function is undefined when the pixmap is being |
|
1799 |
painted on. |
|
1800 |
||
1801 |
\warning This is potentially an expensive operation. Most usecases |
|
1802 |
for this function are covered by QPainter and compositionModes |
|
1803 |
which will normally execute faster. |
|
1804 |
||
1805 |
\sa alphaChannel(), {QPixmap#Pixmap Transformations}{Pixmap |
|
1806 |
Transformations} |
|
1807 |
*/ |
|
1808 |
void QPixmap::setAlphaChannel(const QPixmap &alphaChannel) |
|
1809 |
{ |
|
1810 |
if (alphaChannel.isNull()) |
|
1811 |
return; |
|
1812 |
||
1813 |
if (paintingActive()) { |
|
1814 |
qWarning("QPixmap::setAlphaChannel: " |
|
1815 |
"Cannot set alpha channel while pixmap is being painted on"); |
|
1816 |
return; |
|
1817 |
} |
|
1818 |
||
1819 |
if (width() != alphaChannel.width() && height() != alphaChannel.height()) { |
|
1820 |
qWarning("QPixmap::setAlphaChannel: " |
|
1821 |
"The pixmap and the alpha channel pixmap must have the same size"); |
|
1822 |
return; |
|
1823 |
} |
|
1824 |
||
1825 |
detach(); |
|
1826 |
data->setAlphaChannel(alphaChannel); |
|
1827 |
} |
|
1828 |
||
1829 |
/*! |
|
1830 |
\obsolete |
|
1831 |
||
1832 |
Returns the alpha channel of the pixmap as a new grayscale QPixmap in which |
|
1833 |
each pixel's red, green, and blue values are given the alpha value of the |
|
1834 |
original pixmap. The color depth of the returned pixmap is the system depth |
|
1835 |
on X11 and 8-bit on Windows and Mac OS X. |
|
1836 |
||
1837 |
You can use this function while debugging |
|
1838 |
to get a visible image of the alpha channel. If the pixmap doesn't have an |
|
1839 |
alpha channel, i.e., the alpha channel's value for all pixels equals |
|
1840 |
0xff), a null pixmap is returned. You can check this with the \c isNull() |
|
1841 |
function. |
|
1842 |
||
1843 |
We show an example: |
|
1844 |
||
1845 |
\snippet doc/src/snippets/alphachannel.cpp 0 |
|
1846 |
||
1847 |
\image alphachannelimage.png The pixmap and channelImage QPixmaps |
|
1848 |
||
1849 |
\warning This is an expensive operation. The alpha channel of the |
|
1850 |
pixmap is extracted dynamically from the pixeldata. Most usecases of this |
|
1851 |
function are covered by QPainter and compositionModes which will normally |
|
1852 |
execute faster. |
|
1853 |
||
1854 |
\sa setAlphaChannel(), {QPixmap#Pixmap Information}{Pixmap |
|
1855 |
Information} |
|
1856 |
*/ |
|
1857 |
QPixmap QPixmap::alphaChannel() const |
|
1858 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1859 |
return data ? data->alphaChannel() : QPixmap(); |
0 | 1860 |
} |
1861 |
||
1862 |
/*! |
|
1863 |
\internal |
|
1864 |
*/ |
|
1865 |
QPaintEngine *QPixmap::paintEngine() const |
|
1866 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1867 |
return data ? data->paintEngine() : 0; |
0 | 1868 |
} |
1869 |
||
1870 |
/*! |
|
1871 |
\fn QBitmap QPixmap::mask() const |
|
1872 |
||
1873 |
Extracts a bitmap mask from the pixmap's alpha channel. |
|
1874 |
||
1875 |
\warning This is potentially an expensive operation. The mask of |
|
1876 |
the pixmap is extracted dynamically from the pixeldata. |
|
1877 |
||
1878 |
\sa setMask(), {QPixmap#Pixmap Information}{Pixmap Information} |
|
1879 |
*/ |
|
1880 |
QBitmap QPixmap::mask() const |
|
1881 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1882 |
return data ? data->mask() : QBitmap(); |
0 | 1883 |
} |
1884 |
||
1885 |
/*! |
|
1886 |
Returns the default pixmap depth used by the application. |
|
1887 |
||
1888 |
On Windows and Mac, the default depth is always 32. On X11 and |
|
1889 |
embedded, the depth of the screen will be returned by this |
|
1890 |
function. |
|
1891 |
||
1892 |
\sa depth(), QColormap::depth(), {QPixmap#Pixmap Information}{Pixmap Information} |
|
1893 |
||
1894 |
*/ |
|
1895 |
int QPixmap::defaultDepth() |
|
1896 |
{ |
|
1897 |
#if defined(Q_WS_QWS) |
|
1898 |
return QScreen::instance()->depth(); |
|
1899 |
#elif defined(Q_WS_X11) |
|
1900 |
return QX11Info::appDepth(); |
|
1901 |
#elif defined(Q_WS_WINCE) |
|
1902 |
return QColormap::instance().depth(); |
|
1903 |
#elif defined(Q_WS_WIN) |
|
1904 |
return 32; // XXX |
|
1905 |
#elif defined(Q_WS_MAC) |
|
1906 |
return 32; |
|
1907 |
#elif defined(Q_OS_SYMBIAN) |
|
1908 |
return S60->screenDepth; |
|
1909 |
#endif |
|
1910 |
} |
|
1911 |
||
1912 |
/*! |
|
1913 |
Detaches the pixmap from shared pixmap data. |
|
1914 |
||
1915 |
A pixmap is automatically detached by Qt whenever its contents are |
|
1916 |
about to change. This is done in almost all QPixmap member |
|
1917 |
functions that modify the pixmap (fill(), fromImage(), |
|
1918 |
load(), etc.), and in QPainter::begin() on a pixmap. |
|
1919 |
||
1920 |
There are two exceptions in which detach() must be called |
|
1921 |
explicitly, that is when calling the handle() or the |
|
1922 |
x11PictureHandle() function (only available on X11). Otherwise, |
|
1923 |
any modifications done using system calls, will be performed on |
|
1924 |
the shared data. |
|
1925 |
||
1926 |
The detach() function returns immediately if there is just a |
|
1927 |
single reference or if the pixmap has not been initialized yet. |
|
1928 |
*/ |
|
1929 |
void QPixmap::detach() |
|
1930 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1931 |
if (!data) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1932 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1933 |
|
0 | 1934 |
QPixmapData::ClassId id = data->classId(); |
1935 |
if (id == QPixmapData::RasterClass) { |
|
1936 |
QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data()); |
|
1937 |
rasterData->image.detach(); |
|
1938 |
} |
|
1939 |
||
1940 |
if (data->is_cached && data->ref == 1) |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1941 |
QImagePixmapCleanupHooks::executePixmapDataModificationHooks(data.data()); |
0 | 1942 |
|
1943 |
#if defined(Q_WS_MAC) |
|
1944 |
QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(data.data()) : 0; |
|
1945 |
if (macData) { |
|
1946 |
if (macData->cg_mask) { |
|
1947 |
CGImageRelease(macData->cg_mask); |
|
1948 |
macData->cg_mask = 0; |
|
1949 |
} |
|
1950 |
} |
|
1951 |
#endif |
|
1952 |
||
1953 |
if (data->ref != 1) { |
|
1954 |
*this = copy(); |
|
1955 |
} |
|
1956 |
++data->detach_no; |
|
1957 |
||
1958 |
#if defined(Q_WS_X11) |
|
1959 |
if (data->classId() == QPixmapData::X11Class) { |
|
1960 |
QX11PixmapData *d = static_cast<QX11PixmapData*>(data.data()); |
|
1961 |
d->flags &= ~QX11PixmapData::Uninitialized; |
|
1962 |
||
1963 |
// reset the cache data |
|
1964 |
if (d->hd2) { |
|
1965 |
XFreePixmap(X11->display, d->hd2); |
|
1966 |
d->hd2 = 0; |
|
1967 |
} |
|
1968 |
} |
|
1969 |
#elif defined(Q_WS_MAC) |
|
1970 |
if (macData) { |
|
1971 |
macData->macReleaseCGImageRef(); |
|
1972 |
macData->uninit = false; |
|
1973 |
} |
|
1974 |
#endif |
|
1975 |
} |
|
1976 |
||
1977 |
/*! |
|
1978 |
\fn QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) |
|
1979 |
||
1980 |
Converts the given \a image to a pixmap using the specified \a |
|
1981 |
flags to control the conversion. The \a flags argument is a |
|
1982 |
bitwise-OR of the \l{Qt::ImageConversionFlags}. Passing 0 for \a |
|
1983 |
flags sets all the default options. |
|
1984 |
||
1985 |
In case of monochrome and 8-bit images, the image is first |
|
1986 |
converted to a 32-bit pixmap and then filled with the colors in |
|
1987 |
the color table. If this is too expensive an operation, you can |
|
1988 |
use QBitmap::fromImage() instead. |
|
1989 |
||
1990 |
\sa toImage(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} |
|
1991 |
*/ |
|
1992 |
QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) |
|
1993 |
{ |
|
1994 |
if (image.isNull()) |
|
1995 |
return QPixmap(); |
|
1996 |
||
1997 |
QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem(); |
|
1998 |
QScopedPointer<QPixmapData> data(gs ? gs->createPixmapData(QPixmapData::PixmapType) |
|
1999 |
: QGraphicsSystem::createDefaultPixmapData(QPixmapData::PixmapType)); |
|
2000 |
data->fromImage(image, flags); |
|
2001 |
return QPixmap(data.take()); |
|
2002 |
} |
|
2003 |
||
2004 |
/*! |
|
2005 |
\fn QPixmap QPixmap::grabWindow(WId window, int x, int y, int |
|
2006 |
width, int height) |
|
2007 |
||
2008 |
Creates and returns a pixmap constructed by grabbing the contents |
|
2009 |
of the given \a window restricted by QRect(\a x, \a y, \a width, |
|
2010 |
\a height). |
|
2011 |
||
2012 |
The arguments (\a{x}, \a{y}) specify the offset in the window, |
|
2013 |
whereas (\a{width}, \a{height}) specify the area to be copied. If |
|
2014 |
\a width is negative, the function copies everything to the right |
|
2015 |
border of the window. If \a height is negative, the function |
|
2016 |
copies everything to the bottom of the window. |
|
2017 |
||
2018 |
The window system identifier (\c WId) can be retrieved using the |
|
2019 |
QWidget::winId() function. The rationale for using a window |
|
2020 |
identifier and not a QWidget, is to enable grabbing of windows |
|
2021 |
that are not part of the application, window system frames, and so |
|
2022 |
on. |
|
2023 |
||
2024 |
The grabWindow() function grabs pixels from the screen, not from |
|
2025 |
the window, i.e. if there is another window partially or entirely |
|
2026 |
over the one you grab, you get pixels from the overlying window, |
|
2027 |
too. The mouse cursor is generally not grabbed. |
|
2028 |
||
2029 |
Note on X11that if the given \a window doesn't have the same depth |
|
2030 |
as the root window, and another window partially or entirely |
|
2031 |
obscures the one you grab, you will \e not get pixels from the |
|
2032 |
overlying window. The contents of the obscured areas in the |
|
2033 |
pixmap will be undefined and uninitialized. |
|
2034 |
||
2035 |
\warning In general, grabbing an area outside the screen is not |
|
2036 |
safe. This depends on the underlying window system. |
|
2037 |
||
2038 |
\sa grabWidget(), {Screenshot Example} |
|
2039 |
*/ |
|
2040 |
||
2041 |
/*! |
|
2042 |
\internal |
|
2043 |
*/ |
|
2044 |
QPixmapData* QPixmap::pixmapData() const |
|
2045 |
{ |
|
2046 |
return data.data(); |
|
2047 |
} |
|
2048 |
||
2049 |
/*! |
|
2050 |
\enum QPixmap::HBitmapFormat |
|
2051 |
||
2052 |
\bold{Win32 only:} This enum defines how the conversion between \c |
|
2053 |
HBITMAP and QPixmap is performed. |
|
2054 |
||
2055 |
\warning This enum is only available on Windows. |
|
2056 |
||
2057 |
\value NoAlpha The alpha channel is ignored and always treated as |
|
2058 |
being set to fully opaque. This is preferred if the \c HBITMAP is |
|
2059 |
used with standard GDI calls, such as \c BitBlt(). |
|
2060 |
||
2061 |
\value PremultipliedAlpha The \c HBITMAP is treated as having an |
|
2062 |
alpha channel and premultiplied colors. This is preferred if the |
|
2063 |
\c HBITMAP is accessed through the \c AlphaBlend() GDI function. |
|
2064 |
||
2065 |
\value Alpha The \c HBITMAP is treated as having a plain alpha |
|
2066 |
channel. This is the preferred format if the \c HBITMAP is going |
|
2067 |
to be used as an application icon or systray icon. |
|
2068 |
||
2069 |
\sa fromWinHBITMAP(), toWinHBITMAP() |
|
2070 |
*/ |
|
2071 |
||
2072 |
/*! \fn HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const |
|
2073 |
\bold{Win32 only:} Creates a \c HBITMAP equivalent to the QPixmap, |
|
2074 |
based on the given \a format. Returns the \c HBITMAP handle. |
|
2075 |
||
2076 |
It is the caller's responsibility to free the \c HBITMAP data |
|
2077 |
after use. |
|
2078 |
||
2079 |
\warning This function is only available on Windows. |
|
2080 |
||
2081 |
\sa fromWinHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} |
|
2082 |
*/ |
|
2083 |
||
2084 |
/*! \fn QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format) |
|
2085 |
\bold{Win32 only:} Returns a QPixmap that is equivalent to the |
|
2086 |
given \a bitmap. The conversion is based on the specified \a |
|
2087 |
format. |
|
2088 |
||
2089 |
\warning This function is only available on Windows. |
|
2090 |
||
2091 |
\sa toWinHBITMAP(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} |
|
2092 |
||
2093 |
*/ |
|
2094 |
||
2095 |
/*! \fn HICON QPixmap::toWinHICON() const |
|
2096 |
\since 4.6 |
|
2097 |
||
2098 |
\bold{Win32 only:} Creates a \c HICON equivalent to the QPixmap. |
|
2099 |
Returns the \c HICON handle. |
|
2100 |
||
2101 |
It is the caller's responsibility to free the \c HICON data after use. |
|
2102 |
||
2103 |
\warning This function is only available on Windows. |
|
2104 |
||
2105 |
\sa fromWinHICON(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} |
|
2106 |
*/ |
|
2107 |
||
2108 |
/*! \fn QPixmap QPixmap::fromWinHICON(HICON icon) |
|
2109 |
\since 4.6 |
|
2110 |
||
2111 |
\bold{Win32 only:} Returns a QPixmap that is equivalent to the given |
|
2112 |
\a icon. |
|
2113 |
||
2114 |
\warning This function is only available on Windows. |
|
2115 |
||
2116 |
\sa toWinHICON(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} |
|
2117 |
||
2118 |
*/ |
|
2119 |
||
2120 |
/*! \fn const QX11Info &QPixmap::x11Info() const |
|
2121 |
\bold{X11 only:} Returns information about the configuration of |
|
2122 |
the X display used by the screen to which the pixmap currently belongs. |
|
2123 |
||
2124 |
\warning This function is only available on X11. |
|
2125 |
||
2126 |
\sa {QPixmap#Pixmap Information}{Pixmap Information} |
|
2127 |
*/ |
|
2128 |
||
2129 |
/*! \fn Qt::HANDLE QPixmap::x11PictureHandle() const |
|
2130 |
\bold{X11 only:} Returns the X11 Picture handle of the pixmap for |
|
2131 |
XRender support. |
|
2132 |
||
2133 |
This function will return 0 if XRender support is not compiled |
|
2134 |
into Qt, if the XRender extension is not supported on the X11 |
|
2135 |
display, or if the handle could not be created. Use of this |
|
2136 |
function is not portable. |
|
2137 |
||
2138 |
\warning This function is only available on X11. |
|
2139 |
||
2140 |
\sa {QPixmap#Pixmap Information}{Pixmap Information} |
|
2141 |
*/ |
|
2142 |
||
2143 |
/*! \fn int QPixmap::x11SetDefaultScreen(int screen) |
|
2144 |
\internal |
|
2145 |
*/ |
|
2146 |
||
2147 |
/*! \fn void QPixmap::x11SetScreen(int screen) |
|
2148 |
\internal |
|
2149 |
*/ |
|
2150 |
||
2151 |
/*! \fn QRgb* QPixmap::clut() const |
|
2152 |
\internal |
|
2153 |
*/ |
|
2154 |
||
2155 |
/*! \fn int QPixmap::numCols() const |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2156 |
\obsolete |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2157 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2158 |
\sa colorCount() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2159 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2160 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2161 |
/*! \fn int QPixmap::colorCount() const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2162 |
\since 4.6 |
0 | 2163 |
\internal |
2164 |
*/ |
|
2165 |
||
2166 |
/*! \fn const uchar* QPixmap::qwsBits() const |
|
2167 |
\internal |
|
2168 |
\since 4.1 |
|
2169 |
*/ |
|
2170 |
||
2171 |
/*! \fn int QPixmap::qwsBytesPerLine() const |
|
2172 |
\internal |
|
2173 |
\since 4.1 |
|
2174 |
*/ |
|
2175 |
||
2176 |
QT_END_NAMESPACE |