| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/image/qpixmap.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include <qglobal.h> | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #include "qpixmap.h" | - | ||||||||||||||||||
| 37 | #include <qpa/qplatformpixmap.h> | - | ||||||||||||||||||
| 38 | #include "qimagepixmapcleanuphooks_p.h" | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qbitmap.h" | - | ||||||||||||||||||
| 41 | #include "qimage.h" | - | ||||||||||||||||||
| 42 | #include "qpainter.h" | - | ||||||||||||||||||
| 43 | #include "qdatastream.h" | - | ||||||||||||||||||
| 44 | #include "qbuffer.h" | - | ||||||||||||||||||
| 45 | #include <private/qguiapplication_p.h> | - | ||||||||||||||||||
| 46 | #include "qevent.h" | - | ||||||||||||||||||
| 47 | #include "qfile.h" | - | ||||||||||||||||||
| 48 | #include "qfileinfo.h" | - | ||||||||||||||||||
| 49 | #include "qpixmapcache.h" | - | ||||||||||||||||||
| 50 | #include "qdatetime.h" | - | ||||||||||||||||||
| 51 | #include "qimagereader.h" | - | ||||||||||||||||||
| 52 | #include "qimagewriter.h" | - | ||||||||||||||||||
| 53 | #include "qpaintengine.h" | - | ||||||||||||||||||
| 54 | #include "qscreen.h" | - | ||||||||||||||||||
| 55 | #include "qthread.h" | - | ||||||||||||||||||
| 56 | #include "qdebug.h" | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | #include <qpa/qplatformintegration.h> | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | #include "qpixmap_raster_p.h" | - | ||||||||||||||||||
| 61 | #include "private/qhexstring_p.h" | - | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | static bool qt_pixmap_thread_test() | - | ||||||||||||||||||
| 66 | { | - | ||||||||||||||||||
| 67 | if (!QCoreApplication::instance()) {
| 0 | ||||||||||||||||||
| 68 | qFatal("QPixmap: Must construct a QGuiApplication before a QPixmap"); | - | ||||||||||||||||||
| 69 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 70 | } | - | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | if (qApp->thread() != QThread::currentThread()) {
| 0 | ||||||||||||||||||
| 73 | bool fail = false; | - | ||||||||||||||||||
| 74 | if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) {
| 0 | ||||||||||||||||||
| 75 | printf("Lighthouse plugin does not support threaded pixmaps!\n"); | - | ||||||||||||||||||
| 76 | fail = true; | - | ||||||||||||||||||
| 77 | } never executed: end of block | 0 | ||||||||||||||||||
| 78 | if (fail) {
| 0 | ||||||||||||||||||
| 79 | qWarning("QPixmap: It is not safe to use pixmaps outside the GUI thread"); | - | ||||||||||||||||||
| 80 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 81 | } | - | ||||||||||||||||||
| 82 | } never executed: end of block | 0 | ||||||||||||||||||
| 83 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 84 | } | - | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | void QPixmap::doInit(int w, int h, int type) | - | ||||||||||||||||||
| 87 | { | - | ||||||||||||||||||
| 88 | if ((w > 0 && h > 0) || type == QPlatformPixmap::BitmapType)
| 0 | ||||||||||||||||||
| 89 | data = QPlatformPixmap::create(w, h, (QPlatformPixmap::PixelType) type); never executed: data = QPlatformPixmap::create(w, h, (QPlatformPixmap::PixelType) type); | 0 | ||||||||||||||||||
| 90 | else | - | ||||||||||||||||||
| 91 | data = 0; never executed: data = 0; | 0 | ||||||||||||||||||
| 92 | } | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | /*! | - | ||||||||||||||||||
| 95 | Constructs a null pixmap. | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | \sa isNull() | - | ||||||||||||||||||
| 98 | */ | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | QPixmap::QPixmap() | - | ||||||||||||||||||
| 101 | : QPaintDevice() | - | ||||||||||||||||||
| 102 | { | - | ||||||||||||||||||
| 103 | (void) qt_pixmap_thread_test(); | - | ||||||||||||||||||
| 104 | doInit(0, 0, QPlatformPixmap::PixmapType); | - | ||||||||||||||||||
| 105 | } never executed: end of block | 0 | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | /*! | - | ||||||||||||||||||
| 108 | \fn QPixmap::QPixmap(int width, int height) | - | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | Constructs a pixmap with the given \a width and \a height. If | - | ||||||||||||||||||
| 111 | either \a width or \a height is zero, a null pixmap is | - | ||||||||||||||||||
| 112 | constructed. | - | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | \warning This will create a QPixmap with uninitialized data. Call | - | ||||||||||||||||||
| 115 | fill() to fill the pixmap with an appropriate color before drawing | - | ||||||||||||||||||
| 116 | onto it with QPainter. | - | ||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | \sa isNull() | - | ||||||||||||||||||
| 119 | */ | - | ||||||||||||||||||
| 120 | - | |||||||||||||||||||
| 121 | QPixmap::QPixmap(int w, int h) | - | ||||||||||||||||||
| 122 | : QPaintDevice() | - | ||||||||||||||||||
| 123 | { | - | ||||||||||||||||||
| 124 | if (!qt_pixmap_thread_test())
| 0 | ||||||||||||||||||
| 125 | doInit(0, 0, QPlatformPixmap::PixmapType); never executed: doInit(0, 0, QPlatformPixmap::PixmapType); | 0 | ||||||||||||||||||
| 126 | else | - | ||||||||||||||||||
| 127 | doInit(w, h, QPlatformPixmap::PixmapType); never executed: doInit(w, h, QPlatformPixmap::PixmapType); | 0 | ||||||||||||||||||
| 128 | } | - | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | /*! | - | ||||||||||||||||||
| 131 | \overload | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | Constructs a pixmap of the given \a size. | - | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | \warning This will create a QPixmap with uninitialized data. Call | - | ||||||||||||||||||
| 136 | fill() to fill the pixmap with an appropriate color before drawing | - | ||||||||||||||||||
| 137 | onto it with QPainter. | - | ||||||||||||||||||
| 138 | */ | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | QPixmap::QPixmap(const QSize &size) | - | ||||||||||||||||||
| 141 | : QPaintDevice() | - | ||||||||||||||||||
| 142 | { | - | ||||||||||||||||||
| 143 | if (!qt_pixmap_thread_test())
| 0 | ||||||||||||||||||
| 144 | doInit(0, 0, QPlatformPixmap::PixmapType); never executed: doInit(0, 0, QPlatformPixmap::PixmapType); | 0 | ||||||||||||||||||
| 145 | else | - | ||||||||||||||||||
| 146 | doInit(size.width(), size.height(), QPlatformPixmap::PixmapType); never executed: doInit(size.width(), size.height(), QPlatformPixmap::PixmapType); | 0 | ||||||||||||||||||
| 147 | } | - | ||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | /*! | - | ||||||||||||||||||
| 150 | \internal | - | ||||||||||||||||||
| 151 | */ | - | ||||||||||||||||||
| 152 | QPixmap::QPixmap(const QSize &s, int type) | - | ||||||||||||||||||
| 153 | { | - | ||||||||||||||||||
| 154 | if (!qt_pixmap_thread_test())
| 0 | ||||||||||||||||||
| 155 | doInit(0, 0, static_cast<QPlatformPixmap::PixelType>(type)); never executed: doInit(0, 0, static_cast<QPlatformPixmap::PixelType>(type)); | 0 | ||||||||||||||||||
| 156 | else | - | ||||||||||||||||||
| 157 | doInit(s.width(), s.height(), static_cast<QPlatformPixmap::PixelType>(type)); never executed: doInit(s.width(), s.height(), static_cast<QPlatformPixmap::PixelType>(type)); | 0 | ||||||||||||||||||
| 158 | } | - | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | /*! | - | ||||||||||||||||||
| 161 | \internal | - | ||||||||||||||||||
| 162 | */ | - | ||||||||||||||||||
| 163 | QPixmap::QPixmap(QPlatformPixmap *d) | - | ||||||||||||||||||
| 164 | : QPaintDevice(), data(d) | - | ||||||||||||||||||
| 165 | { | - | ||||||||||||||||||
| 166 | } never executed: end of block | 0 | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | /*! | - | ||||||||||||||||||
| 169 | Constructs a pixmap from the file with the given \a fileName. If the | - | ||||||||||||||||||
| 170 | file does not exist or is of an unknown format, the pixmap becomes a | - | ||||||||||||||||||
| 171 | null pixmap. | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | The loader attempts to read the pixmap using the specified \a | - | ||||||||||||||||||
| 174 | format. If the \a format is not specified (which is the default), | - | ||||||||||||||||||
| 175 | the loader probes the file for a header to guess the file format. | - | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | The file name can either refer to an actual file on disk or to | - | ||||||||||||||||||
| 178 | one of the application's embedded resources. See the | - | ||||||||||||||||||
| 179 | \l{resources.html}{Resource System} overview for details on how | - | ||||||||||||||||||
| 180 | to embed images and other resource files in the application's | - | ||||||||||||||||||
| 181 | executable. | - | ||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | If the image needs to be modified to fit in a lower-resolution | - | ||||||||||||||||||
| 184 | result (e.g. converting from 32-bit to 8-bit), use the \a | - | ||||||||||||||||||
| 185 | flags to control the conversion. | - | ||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | The \a fileName, \a format and \a flags parameters are | - | ||||||||||||||||||
| 188 | passed on to load(). This means that the data in \a fileName is | - | ||||||||||||||||||
| 189 | not compiled into the binary. If \a fileName contains a relative | - | ||||||||||||||||||
| 190 | path (e.g. the filename only) the relevant file must be found | - | ||||||||||||||||||
| 191 | relative to the runtime working directory. | - | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | \sa {QPixmap#Reading and Writing Image Files}{Reading and Writing | - | ||||||||||||||||||
| 194 | Image Files} | - | ||||||||||||||||||
| 195 | */ | - | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | QPixmap::QPixmap(const QString& fileName, const char *format, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 198 | : QPaintDevice() | - | ||||||||||||||||||
| 199 | { | - | ||||||||||||||||||
| 200 | doInit(0, 0, QPlatformPixmap::PixmapType); | - | ||||||||||||||||||
| 201 | if (!qt_pixmap_thread_test())
| 0 | ||||||||||||||||||
| 202 | return; never executed: return; | 0 | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | load(fileName, format, flags); | - | ||||||||||||||||||
| 205 | } never executed: end of block | 0 | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | /*! | - | ||||||||||||||||||
| 208 | Constructs a pixmap that is a copy of the given \a pixmap. | - | ||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | \sa copy() | - | ||||||||||||||||||
| 211 | */ | - | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | QPixmap::QPixmap(const QPixmap &pixmap) | - | ||||||||||||||||||
| 214 | : QPaintDevice() | - | ||||||||||||||||||
| 215 | { | - | ||||||||||||||||||
| 216 | if (!qt_pixmap_thread_test()) {
| 0 | ||||||||||||||||||
| 217 | doInit(0, 0, QPlatformPixmap::PixmapType); | - | ||||||||||||||||||
| 218 | return; never executed: return; | 0 | ||||||||||||||||||
| 219 | } | - | ||||||||||||||||||
| 220 | if (pixmap.paintingActive()) { // make a deep copy
| 0 | ||||||||||||||||||
| 221 | pixmap.copy().swap(*this); | - | ||||||||||||||||||
| 222 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 223 | data = pixmap.data; | - | ||||||||||||||||||
| 224 | } never executed: end of block | 0 | ||||||||||||||||||
| 225 | } | - | ||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | /*! | - | ||||||||||||||||||
| 228 | Constructs a pixmap from the given \a xpm data, which must be a | - | ||||||||||||||||||
| 229 | valid XPM image. | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | Errors are silently ignored. | - | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | Note that it's possible to squeeze the XPM variable a little bit | - | ||||||||||||||||||
| 234 | by using an unusual declaration: | - | ||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | \snippet code/src_gui_image_qpixmap.cpp 0 | - | ||||||||||||||||||
| 237 | - | |||||||||||||||||||
| 238 | The extra \c const makes the entire definition read-only, which is | - | ||||||||||||||||||
| 239 | slightly more efficient (for example, when the code is in a shared | - | ||||||||||||||||||
| 240 | library) and ROMable when the application is to be stored in ROM. | - | ||||||||||||||||||
| 241 | */ | - | ||||||||||||||||||
| 242 | #ifndef QT_NO_IMAGEFORMAT_XPM | - | ||||||||||||||||||
| 243 | QPixmap::QPixmap(const char * const xpm[]) | - | ||||||||||||||||||
| 244 | : QPaintDevice() | - | ||||||||||||||||||
| 245 | { | - | ||||||||||||||||||
| 246 | doInit(0, 0, QPlatformPixmap::PixmapType); | - | ||||||||||||||||||
| 247 | if (!xpm)
| 0 | ||||||||||||||||||
| 248 | return; never executed: return; | 0 | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | QImage image(xpm); | - | ||||||||||||||||||
| 251 | if (!image.isNull()) {
| 0 | ||||||||||||||||||
| 252 | if (data && data->pixelType() == QPlatformPixmap::BitmapType)
| 0 | ||||||||||||||||||
| 253 | *this = QBitmap::fromImage(image); never executed: *this = QBitmap::fromImage(image); | 0 | ||||||||||||||||||
| 254 | else | - | ||||||||||||||||||
| 255 | *this = fromImage(image); never executed: *this = fromImage(image); | 0 | ||||||||||||||||||
| 256 | } | - | ||||||||||||||||||
| 257 | } never executed: end of block | 0 | ||||||||||||||||||
| 258 | #endif | - | ||||||||||||||||||
| 259 | - | |||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | /*! | - | ||||||||||||||||||
| 262 | Destroys the pixmap. | - | ||||||||||||||||||
| 263 | */ | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | QPixmap::~QPixmap() | - | ||||||||||||||||||
| 266 | { | - | ||||||||||||||||||
| 267 | Q_ASSERT(!data || data->ref.load() >= 1); // Catch if ref-counting changes again | - | ||||||||||||||||||
| 268 | } never executed: end of block | 0 | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | /*! | - | ||||||||||||||||||
| 271 | \internal | - | ||||||||||||||||||
| 272 | */ | - | ||||||||||||||||||
| 273 | int QPixmap::devType() const | - | ||||||||||||||||||
| 274 | { | - | ||||||||||||||||||
| 275 | return QInternal::Pixmap; never executed: return QInternal::Pixmap; | 0 | ||||||||||||||||||
| 276 | } | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | /*! | - | ||||||||||||||||||
| 279 | \fn QPixmap QPixmap::copy(int x, int y, int width, int height) const | - | ||||||||||||||||||
| 280 | \overload | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | Returns a deep copy of the subset of the pixmap that is specified | - | ||||||||||||||||||
| 283 | by the rectangle QRect( \a x, \a y, \a width, \a height). | - | ||||||||||||||||||
| 284 | */ | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | /*! | - | ||||||||||||||||||
| 287 | \fn QPixmap QPixmap::copy(const QRect &rectangle) const | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | Returns a deep copy of the subset of the pixmap that is specified | - | ||||||||||||||||||
| 290 | by the given \a rectangle. For more information on deep copies, | - | ||||||||||||||||||
| 291 | see the \l {Implicit Data Sharing} documentation. | - | ||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | If the given \a rectangle is empty, the whole image is copied. | - | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | \sa operator=(), QPixmap(), {QPixmap#Pixmap | - | ||||||||||||||||||
| 296 | Transformations}{Pixmap Transformations} | - | ||||||||||||||||||
| 297 | */ | - | ||||||||||||||||||
| 298 | QPixmap QPixmap::copy(const QRect &rect) const | - | ||||||||||||||||||
| 299 | { | - | ||||||||||||||||||
| 300 | if (isNull())
| 0 | ||||||||||||||||||
| 301 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | QRect r(0, 0, width(), height()); | - | ||||||||||||||||||
| 304 | if (!rect.isEmpty())
| 0 | ||||||||||||||||||
| 305 | r = r.intersected(rect); never executed: r = r.intersected(rect); | 0 | ||||||||||||||||||
| 306 | - | |||||||||||||||||||
| 307 | QPlatformPixmap *d = data->createCompatiblePlatformPixmap(); | - | ||||||||||||||||||
| 308 | d->copy(data.data(), r); | - | ||||||||||||||||||
| 309 | return QPixmap(d); never executed: return QPixmap(d); | 0 | ||||||||||||||||||
| 310 | } | - | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | /*! | - | ||||||||||||||||||
| 313 | \fn QPixmap::scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed) | - | ||||||||||||||||||
| 314 | \since 4.6 | - | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | This convenience function is equivalent to calling QPixmap::scroll(\a dx, | - | ||||||||||||||||||
| 317 | \a dy, QRect(\a x, \a y, \a width, \a height), \a exposed). | - | ||||||||||||||||||
| 318 | - | |||||||||||||||||||
| 319 | \sa QWidget::scroll(), QGraphicsItem::scroll() | - | ||||||||||||||||||
| 320 | */ | - | ||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | /*! | - | ||||||||||||||||||
| 323 | \since 4.6 | - | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | Scrolls the area \a rect of this pixmap by (\a dx, \a dy). The exposed | - | ||||||||||||||||||
| 326 | region is left unchanged. You can optionally pass a pointer to an empty | - | ||||||||||||||||||
| 327 | QRegion to get the region that is \a exposed by the scroll operation. | - | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | \snippet code/src_gui_image_qpixmap.cpp 2 | - | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | You cannot scroll while there is an active painter on the pixmap. | - | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | \sa QWidget::scroll(), QGraphicsItem::scroll() | - | ||||||||||||||||||
| 334 | */ | - | ||||||||||||||||||
| 335 | void QPixmap::scroll(int dx, int dy, const QRect &rect, QRegion *exposed) | - | ||||||||||||||||||
| 336 | { | - | ||||||||||||||||||
| 337 | if (isNull() || (dx == 0 && dy == 0))
| 0 | ||||||||||||||||||
| 338 | return; never executed: return; | 0 | ||||||||||||||||||
| 339 | QRect dest = rect & this->rect(); | - | ||||||||||||||||||
| 340 | QRect src = dest.translated(-dx, -dy) & dest; | - | ||||||||||||||||||
| 341 | if (src.isEmpty()) {
| 0 | ||||||||||||||||||
| 342 | if (exposed)
| 0 | ||||||||||||||||||
| 343 | *exposed += dest; never executed: *exposed += dest; | 0 | ||||||||||||||||||
| 344 | return; never executed: return; | 0 | ||||||||||||||||||
| 345 | } | - | ||||||||||||||||||
| 346 | - | |||||||||||||||||||
| 347 | detach(); | - | ||||||||||||||||||
| 348 | - | |||||||||||||||||||
| 349 | if (!data->scroll(dx, dy, src)) {
| 0 | ||||||||||||||||||
| 350 | // Fallback | - | ||||||||||||||||||
| 351 | QPixmap pix = *this; | - | ||||||||||||||||||
| 352 | QPainter painter(&pix); | - | ||||||||||||||||||
| 353 | painter.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||||||||||||||
| 354 | painter.drawPixmap(src.translated(dx, dy), *this, src); | - | ||||||||||||||||||
| 355 | painter.end(); | - | ||||||||||||||||||
| 356 | *this = pix; | - | ||||||||||||||||||
| 357 | } never executed: end of block | 0 | ||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | if (exposed) {
| 0 | ||||||||||||||||||
| 360 | *exposed += dest; | - | ||||||||||||||||||
| 361 | *exposed -= src.translated(dx, dy); | - | ||||||||||||||||||
| 362 | } never executed: end of block | 0 | ||||||||||||||||||
| 363 | } never executed: end of block | 0 | ||||||||||||||||||
| 364 | - | |||||||||||||||||||
| 365 | /*! | - | ||||||||||||||||||
| 366 | Assigns the given \a pixmap to this pixmap and returns a reference | - | ||||||||||||||||||
| 367 | to this pixmap. | - | ||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | \sa copy(), QPixmap() | - | ||||||||||||||||||
| 370 | */ | - | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | QPixmap &QPixmap::operator=(const QPixmap &pixmap) | - | ||||||||||||||||||
| 373 | { | - | ||||||||||||||||||
| 374 | if (paintingActive()) {
| 0 | ||||||||||||||||||
| 375 | qWarning("QPixmap::operator=: Cannot assign to pixmap during painting"); | - | ||||||||||||||||||
| 376 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 377 | } | - | ||||||||||||||||||
| 378 | if (pixmap.paintingActive()) { // make a deep copy
| 0 | ||||||||||||||||||
| 379 | pixmap.copy().swap(*this); | - | ||||||||||||||||||
| 380 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 381 | data = pixmap.data; | - | ||||||||||||||||||
| 382 | } never executed: end of block | 0 | ||||||||||||||||||
| 383 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 384 | } | - | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | /*! | - | ||||||||||||||||||
| 387 | \fn QPixmap &QPixmap::operator=(QPixmap &&other) | - | ||||||||||||||||||
| 388 | - | |||||||||||||||||||
| 389 | Move-assigns \a other to this QPixmap instance. | - | ||||||||||||||||||
| 390 | - | |||||||||||||||||||
| 391 | \since 5.2 | - | ||||||||||||||||||
| 392 | */ | - | ||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | /*! | - | ||||||||||||||||||
| 395 | \fn void QPixmap::swap(QPixmap &other) | - | ||||||||||||||||||
| 396 | \since 4.8 | - | ||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | Swaps pixmap \a other with this pixmap. This operation is very | - | ||||||||||||||||||
| 399 | fast and never fails. | - | ||||||||||||||||||
| 400 | */ | - | ||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | /*! | - | ||||||||||||||||||
| 403 | Returns the pixmap as a QVariant. | - | ||||||||||||||||||
| 404 | */ | - | ||||||||||||||||||
| 405 | QPixmap::operator QVariant() const | - | ||||||||||||||||||
| 406 | { | - | ||||||||||||||||||
| 407 | return QVariant(QVariant::Pixmap, this); never executed: return QVariant(QVariant::Pixmap, this); | 0 | ||||||||||||||||||
| 408 | } | - | ||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | /*! | - | ||||||||||||||||||
| 411 | \fn bool QPixmap::operator!() const | - | ||||||||||||||||||
| 412 | - | |||||||||||||||||||
| 413 | Returns \c true if this is a null pixmap; otherwise returns \c false. | - | ||||||||||||||||||
| 414 | - | |||||||||||||||||||
| 415 | \sa isNull() | - | ||||||||||||||||||
| 416 | */ | - | ||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | /*! | - | ||||||||||||||||||
| 419 | Converts the pixmap to a QImage. Returns a null image if the | - | ||||||||||||||||||
| 420 | conversion fails. | - | ||||||||||||||||||
| 421 | - | |||||||||||||||||||
| 422 | If the pixmap has 1-bit depth, the returned image will also be 1 | - | ||||||||||||||||||
| 423 | bit deep. Images with more bits will be returned in a format | - | ||||||||||||||||||
| 424 | closely represents the underlying system. Usually this will be | - | ||||||||||||||||||
| 425 | QImage::Format_ARGB32_Premultiplied for pixmaps with an alpha and | - | ||||||||||||||||||
| 426 | QImage::Format_RGB32 or QImage::Format_RGB16 for pixmaps without | - | ||||||||||||||||||
| 427 | alpha. | - | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | Note that for the moment, alpha masks on monochrome images are | - | ||||||||||||||||||
| 430 | ignored. | - | ||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | \sa fromImage(), {QImage#Image Formats}{Image Formats} | - | ||||||||||||||||||
| 433 | */ | - | ||||||||||||||||||
| 434 | QImage QPixmap::toImage() const | - | ||||||||||||||||||
| 435 | { | - | ||||||||||||||||||
| 436 | if (isNull())
| 0 | ||||||||||||||||||
| 437 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | return data->toImage(); never executed: return data->toImage(); | 0 | ||||||||||||||||||
| 440 | } | - | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | /*! | - | ||||||||||||||||||
| 443 | \fn QMatrix QPixmap::trueMatrix(const QTransform &matrix, int width, int height) | - | ||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | Returns the actual matrix used for transforming a pixmap with the | - | ||||||||||||||||||
| 446 | given \a width, \a height and \a matrix. | - | ||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | When transforming a pixmap using the transformed() function, the | - | ||||||||||||||||||
| 449 | transformation matrix is internally adjusted to compensate for | - | ||||||||||||||||||
| 450 | unwanted translation, i.e. transformed() returns the smallest | - | ||||||||||||||||||
| 451 | pixmap containing all transformed points of the original | - | ||||||||||||||||||
| 452 | pixmap. This function returns the modified matrix, which maps | - | ||||||||||||||||||
| 453 | points correctly from the original pixmap into the new pixmap. | - | ||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | \sa transformed(), {QPixmap#Pixmap Transformations}{Pixmap | - | ||||||||||||||||||
| 456 | Transformations} | - | ||||||||||||||||||
| 457 | */ | - | ||||||||||||||||||
| 458 | QTransform QPixmap::trueMatrix(const QTransform &m, int w, int h) | - | ||||||||||||||||||
| 459 | { | - | ||||||||||||||||||
| 460 | return QImage::trueMatrix(m, w, h); never executed: return QImage::trueMatrix(m, w, h); | 0 | ||||||||||||||||||
| 461 | } | - | ||||||||||||||||||
| 462 | - | |||||||||||||||||||
| 463 | /*! | - | ||||||||||||||||||
| 464 | \overload | - | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | This convenience function loads the matrix \a m into a | - | ||||||||||||||||||
| 467 | QTransform and calls the overloaded function with the | - | ||||||||||||||||||
| 468 | QTransform and the width \a w and the height \a h. | - | ||||||||||||||||||
| 469 | */ | - | ||||||||||||||||||
| 470 | QMatrix QPixmap::trueMatrix(const QMatrix &m, int w, int h) | - | ||||||||||||||||||
| 471 | { | - | ||||||||||||||||||
| 472 | return trueMatrix(QTransform(m), w, h).toAffine(); never executed: return trueMatrix(QTransform(m), w, h).toAffine(); | 0 | ||||||||||||||||||
| 473 | } | - | ||||||||||||||||||
| 474 | - | |||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | /*! | - | ||||||||||||||||||
| 477 | \fn bool QPixmap::isQBitmap() const | - | ||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | Returns \c true if this is a QBitmap; otherwise returns \c false. | - | ||||||||||||||||||
| 480 | */ | - | ||||||||||||||||||
| 481 | - | |||||||||||||||||||
| 482 | bool QPixmap::isQBitmap() const | - | ||||||||||||||||||
| 483 | { | - | ||||||||||||||||||
| 484 | return data && data->type == QPlatformPixmap::BitmapType; never executed: return data && data->type == QPlatformPixmap::BitmapType;
| 0 | ||||||||||||||||||
| 485 | } | - | ||||||||||||||||||
| 486 | - | |||||||||||||||||||
| 487 | /*! | - | ||||||||||||||||||
| 488 | \fn bool QPixmap::isNull() const | - | ||||||||||||||||||
| 489 | - | |||||||||||||||||||
| 490 | Returns \c true if this is a null pixmap; otherwise returns \c false. | - | ||||||||||||||||||
| 491 | - | |||||||||||||||||||
| 492 | A null pixmap has zero width, zero height and no contents. You | - | ||||||||||||||||||
| 493 | cannot draw in a null pixmap. | - | ||||||||||||||||||
| 494 | */ | - | ||||||||||||||||||
| 495 | bool QPixmap::isNull() const | - | ||||||||||||||||||
| 496 | { | - | ||||||||||||||||||
| 497 | return !data || data->isNull(); never executed: return !data || data->isNull();
| 0 | ||||||||||||||||||
| 498 | } | - | ||||||||||||||||||
| 499 | - | |||||||||||||||||||
| 500 | /*! | - | ||||||||||||||||||
| 501 | \fn int QPixmap::width() const | - | ||||||||||||||||||
| 502 | - | |||||||||||||||||||
| 503 | Returns the width of the pixmap. | - | ||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | \sa size(), {QPixmap#Pixmap Information}{Pixmap Information} | - | ||||||||||||||||||
| 506 | */ | - | ||||||||||||||||||
| 507 | int QPixmap::width() const | - | ||||||||||||||||||
| 508 | { | - | ||||||||||||||||||
| 509 | return data ? data->width() : 0; never executed: return data ? data->width() : 0;
| 0 | ||||||||||||||||||
| 510 | } | - | ||||||||||||||||||
| 511 | - | |||||||||||||||||||
| 512 | /*! | - | ||||||||||||||||||
| 513 | \fn int QPixmap::height() const | - | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | Returns the height of the pixmap. | - | ||||||||||||||||||
| 516 | - | |||||||||||||||||||
| 517 | \sa size(), {QPixmap#Pixmap Information}{Pixmap Information} | - | ||||||||||||||||||
| 518 | */ | - | ||||||||||||||||||
| 519 | int QPixmap::height() const | - | ||||||||||||||||||
| 520 | { | - | ||||||||||||||||||
| 521 | return data ? data->height() : 0; never executed: return data ? data->height() : 0;
| 0 | ||||||||||||||||||
| 522 | } | - | ||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | /*! | - | ||||||||||||||||||
| 525 | \fn QSize QPixmap::size() const | - | ||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | Returns the size of the pixmap. | - | ||||||||||||||||||
| 528 | - | |||||||||||||||||||
| 529 | \sa width(), height(), {QPixmap#Pixmap Information}{Pixmap | - | ||||||||||||||||||
| 530 | Information} | - | ||||||||||||||||||
| 531 | */ | - | ||||||||||||||||||
| 532 | QSize QPixmap::size() const | - | ||||||||||||||||||
| 533 | { | - | ||||||||||||||||||
| 534 | return data ? QSize(data->width(), data->height()) : QSize(0, 0); never executed: return data ? QSize(data->width(), data->height()) : QSize(0, 0);
| 0 | ||||||||||||||||||
| 535 | } | - | ||||||||||||||||||
| 536 | - | |||||||||||||||||||
| 537 | /*! | - | ||||||||||||||||||
| 538 | \fn QRect QPixmap::rect() const | - | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | Returns the pixmap's enclosing rectangle. | - | ||||||||||||||||||
| 541 | - | |||||||||||||||||||
| 542 | \sa {QPixmap#Pixmap Information}{Pixmap Information} | - | ||||||||||||||||||
| 543 | */ | - | ||||||||||||||||||
| 544 | QRect QPixmap::rect() const | - | ||||||||||||||||||
| 545 | { | - | ||||||||||||||||||
| 546 | return data ? QRect(0, 0, data->width(), data->height()) : QRect(); never executed: return data ? QRect(0, 0, data->width(), data->height()) : QRect();
| 0 | ||||||||||||||||||
| 547 | } | - | ||||||||||||||||||
| 548 | - | |||||||||||||||||||
| 549 | /*! | - | ||||||||||||||||||
| 550 | \fn int QPixmap::depth() const | - | ||||||||||||||||||
| 551 | - | |||||||||||||||||||
| 552 | Returns the depth of the pixmap. | - | ||||||||||||||||||
| 553 | - | |||||||||||||||||||
| 554 | The pixmap depth is also called bits per pixel (bpp) or bit planes | - | ||||||||||||||||||
| 555 | of a pixmap. A null pixmap has depth 0. | - | ||||||||||||||||||
| 556 | - | |||||||||||||||||||
| 557 | \sa defaultDepth(), {QPixmap#Pixmap Information}{Pixmap | - | ||||||||||||||||||
| 558 | Information} | - | ||||||||||||||||||
| 559 | */ | - | ||||||||||||||||||
| 560 | int QPixmap::depth() const | - | ||||||||||||||||||
| 561 | { | - | ||||||||||||||||||
| 562 | return data ? data->depth() : 0; never executed: return data ? data->depth() : 0;
| 0 | ||||||||||||||||||
| 563 | } | - | ||||||||||||||||||
| 564 | - | |||||||||||||||||||
| 565 | /*! | - | ||||||||||||||||||
| 566 | Sets a mask bitmap. | - | ||||||||||||||||||
| 567 | - | |||||||||||||||||||
| 568 | This function merges the \a mask with the pixmap's alpha channel. A pixel | - | ||||||||||||||||||
| 569 | value of 1 on the mask means the pixmap's pixel is unchanged; a value of 0 | - | ||||||||||||||||||
| 570 | means the pixel is transparent. The mask must have the same size as this | - | ||||||||||||||||||
| 571 | pixmap. | - | ||||||||||||||||||
| 572 | - | |||||||||||||||||||
| 573 | Setting a null mask resets the mask, leaving the previously transparent | - | ||||||||||||||||||
| 574 | pixels black. The effect of this function is undefined when the pixmap is | - | ||||||||||||||||||
| 575 | being painted on. | - | ||||||||||||||||||
| 576 | - | |||||||||||||||||||
| 577 | \warning This is potentially an expensive operation. | - | ||||||||||||||||||
| 578 | - | |||||||||||||||||||
| 579 | \sa mask(), {QPixmap#Pixmap Transformations}{Pixmap Transformations}, | - | ||||||||||||||||||
| 580 | QBitmap | - | ||||||||||||||||||
| 581 | */ | - | ||||||||||||||||||
| 582 | void QPixmap::setMask(const QBitmap &mask) | - | ||||||||||||||||||
| 583 | { | - | ||||||||||||||||||
| 584 | if (paintingActive()) {
| 0 | ||||||||||||||||||
| 585 | qWarning("QPixmap::setMask: Cannot set mask while pixmap is being painted on"); | - | ||||||||||||||||||
| 586 | return; never executed: return; | 0 | ||||||||||||||||||
| 587 | } | - | ||||||||||||||||||
| 588 | - | |||||||||||||||||||
| 589 | if (!mask.isNull() && mask.size() != size()) {
| 0 | ||||||||||||||||||
| 590 | qWarning("QPixmap::setMask() mask size differs from pixmap size"); | - | ||||||||||||||||||
| 591 | return; never executed: return; | 0 | ||||||||||||||||||
| 592 | } | - | ||||||||||||||||||
| 593 | - | |||||||||||||||||||
| 594 | if (isNull())
| 0 | ||||||||||||||||||
| 595 | return; never executed: return; | 0 | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask
| 0 | ||||||||||||||||||
| 598 | return; never executed: return; | 0 | ||||||||||||||||||
| 599 | - | |||||||||||||||||||
| 600 | detach(); | - | ||||||||||||||||||
| 601 | - | |||||||||||||||||||
| 602 | QImage image = data->toImage(); | - | ||||||||||||||||||
| 603 | if (mask.size().isEmpty()) {
| 0 | ||||||||||||||||||
| 604 | if (image.depth() != 1) { // hw: ????
| 0 | ||||||||||||||||||
| 605 | image = image.convertToFormat(QImage::Format_RGB32); | - | ||||||||||||||||||
| 606 | } never executed: end of block | 0 | ||||||||||||||||||
| 607 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 608 | const int w = image.width(); | - | ||||||||||||||||||
| 609 | const int h = image.height(); | - | ||||||||||||||||||
| 610 | - | |||||||||||||||||||
| 611 | switch (image.depth()) { | - | ||||||||||||||||||
| 612 | case 1: { never executed: case 1: | 0 | ||||||||||||||||||
| 613 | const QImage imageMask = mask.toImage().convertToFormat(image.format()); | - | ||||||||||||||||||
| 614 | for (int y = 0; y < h; ++y) {
| 0 | ||||||||||||||||||
| 615 | const uchar *mscan = imageMask.scanLine(y); | - | ||||||||||||||||||
| 616 | uchar *tscan = image.scanLine(y); | - | ||||||||||||||||||
| 617 | int bytesPerLine = image.bytesPerLine(); | - | ||||||||||||||||||
| 618 | for (int i = 0; i < bytesPerLine; ++i)
| 0 | ||||||||||||||||||
| 619 | tscan[i] &= mscan[i]; never executed: tscan[i] &= mscan[i]; | 0 | ||||||||||||||||||
| 620 | } never executed: end of block | 0 | ||||||||||||||||||
| 621 | break; never executed: break; | 0 | ||||||||||||||||||
| 622 | } | - | ||||||||||||||||||
| 623 | default: { never executed: default: | 0 | ||||||||||||||||||
| 624 | const QImage imageMask = mask.toImage().convertToFormat(QImage::Format_MonoLSB); | - | ||||||||||||||||||
| 625 | image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); | - | ||||||||||||||||||
| 626 | for (int y = 0; y < h; ++y) {
| 0 | ||||||||||||||||||
| 627 | const uchar *mscan = imageMask.scanLine(y); | - | ||||||||||||||||||
| 628 | QRgb *tscan = (QRgb *)image.scanLine(y); | - | ||||||||||||||||||
| 629 | for (int x = 0; x < w; ++x) {
| 0 | ||||||||||||||||||
| 630 | if (!(mscan[x>>3] & (1 << (x&7))))
| 0 | ||||||||||||||||||
| 631 | tscan[x] = 0; never executed: tscan[x] = 0; | 0 | ||||||||||||||||||
| 632 | } never executed: end of block | 0 | ||||||||||||||||||
| 633 | } never executed: end of block | 0 | ||||||||||||||||||
| 634 | break; never executed: break; | 0 | ||||||||||||||||||
| 635 | } | - | ||||||||||||||||||
| 636 | } | - | ||||||||||||||||||
| 637 | } | - | ||||||||||||||||||
| 638 | data->fromImage(image, Qt::AutoColor); | - | ||||||||||||||||||
| 639 | } never executed: end of block | 0 | ||||||||||||||||||
| 640 | - | |||||||||||||||||||
| 641 | /*! | - | ||||||||||||||||||
| 642 | Returns the device pixel ratio for the pixmap. This is the | - | ||||||||||||||||||
| 643 | ratio between \e{device pixels} and \e{device independent pixels}. | - | ||||||||||||||||||
| 644 | - | |||||||||||||||||||
| 645 | Use this function when calculating layout geometry based on | - | ||||||||||||||||||
| 646 | the pixmap size: QSize layoutSize = image.size() / image.devicePixelRatio() | - | ||||||||||||||||||
| 647 | - | |||||||||||||||||||
| 648 | The default value is 1.0. | - | ||||||||||||||||||
| 649 | - | |||||||||||||||||||
| 650 | \sa setDevicePixelRatio(), QImageReader | - | ||||||||||||||||||
| 651 | */ | - | ||||||||||||||||||
| 652 | qreal QPixmap::devicePixelRatio() const | - | ||||||||||||||||||
| 653 | { | - | ||||||||||||||||||
| 654 | if (!data)
| 0 | ||||||||||||||||||
| 655 | return qreal(1.0); never executed: return qreal(1.0); | 0 | ||||||||||||||||||
| 656 | return data->devicePixelRatio(); never executed: return data->devicePixelRatio(); | 0 | ||||||||||||||||||
| 657 | } | - | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | /*! | - | ||||||||||||||||||
| 660 | Sets the device pixel ratio for the pixmap. This is the | - | ||||||||||||||||||
| 661 | ratio between image pixels and device-independent pixels. | - | ||||||||||||||||||
| 662 | - | |||||||||||||||||||
| 663 | The default \a scaleFactor is 1.0. Setting it to something else has | - | ||||||||||||||||||
| 664 | two effects: | - | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | QPainters that are opened on the pixmap will be scaled. For | - | ||||||||||||||||||
| 667 | example, painting on a 200x200 image if with a ratio of 2.0 | - | ||||||||||||||||||
| 668 | will result in effective (device-independent) painting bounds | - | ||||||||||||||||||
| 669 | of 100x100. | - | ||||||||||||||||||
| 670 | - | |||||||||||||||||||
| 671 | Code paths in Qt that calculate layout geometry based on the | - | ||||||||||||||||||
| 672 | pixmap size will take the ratio into account: | - | ||||||||||||||||||
| 673 | QSize layoutSize = pixmap.size() / pixmap.devicePixelRatio() | - | ||||||||||||||||||
| 674 | The net effect of this is that the pixmap is displayed as | - | ||||||||||||||||||
| 675 | high-DPI pixmap rather than a large pixmap | - | ||||||||||||||||||
| 676 | (see \l{Drawing High Resolution Versions of Pixmaps and Images}). | - | ||||||||||||||||||
| 677 | - | |||||||||||||||||||
| 678 | \sa devicePixelRatio() | - | ||||||||||||||||||
| 679 | */ | - | ||||||||||||||||||
| 680 | void QPixmap::setDevicePixelRatio(qreal scaleFactor) | - | ||||||||||||||||||
| 681 | { | - | ||||||||||||||||||
| 682 | if (isNull())
| 0 | ||||||||||||||||||
| 683 | return; never executed: return; | 0 | ||||||||||||||||||
| 684 | - | |||||||||||||||||||
| 685 | if (scaleFactor == data->devicePixelRatio())
| 0 | ||||||||||||||||||
| 686 | return; never executed: return; | 0 | ||||||||||||||||||
| 687 | - | |||||||||||||||||||
| 688 | detach(); | - | ||||||||||||||||||
| 689 | data->setDevicePixelRatio(scaleFactor); | - | ||||||||||||||||||
| 690 | } never executed: end of block | 0 | ||||||||||||||||||
| 691 | - | |||||||||||||||||||
| 692 | #ifndef QT_NO_IMAGE_HEURISTIC_MASK | - | ||||||||||||||||||
| 693 | /*! | - | ||||||||||||||||||
| 694 | Creates and returns a heuristic mask for this pixmap. | - | ||||||||||||||||||
| 695 | - | |||||||||||||||||||
| 696 | The function works by selecting a color from one of the corners | - | ||||||||||||||||||
| 697 | and then chipping away pixels of that color, starting at all the | - | ||||||||||||||||||
| 698 | edges. If \a clipTight is true (the default) the mask is just | - | ||||||||||||||||||
| 699 | large enough to cover the pixels; otherwise, the mask is larger | - | ||||||||||||||||||
| 700 | than the data pixels. | - | ||||||||||||||||||
| 701 | - | |||||||||||||||||||
| 702 | The mask may not be perfect but it should be reasonable, so you | - | ||||||||||||||||||
| 703 | can do things such as the following: | - | ||||||||||||||||||
| 704 | - | |||||||||||||||||||
| 705 | \snippet code/src_gui_image_qpixmap.cpp 1 | - | ||||||||||||||||||
| 706 | - | |||||||||||||||||||
| 707 | This function is slow because it involves converting to/from a | - | ||||||||||||||||||
| 708 | QImage, and non-trivial computations. | - | ||||||||||||||||||
| 709 | - | |||||||||||||||||||
| 710 | \sa QImage::createHeuristicMask(), createMaskFromColor() | - | ||||||||||||||||||
| 711 | */ | - | ||||||||||||||||||
| 712 | QBitmap QPixmap::createHeuristicMask(bool clipTight) const | - | ||||||||||||||||||
| 713 | { | - | ||||||||||||||||||
| 714 | QBitmap m = QBitmap::fromImage(toImage().createHeuristicMask(clipTight)); | - | ||||||||||||||||||
| 715 | return m; never executed: return m; | 0 | ||||||||||||||||||
| 716 | } | - | ||||||||||||||||||
| 717 | #endif | - | ||||||||||||||||||
| 718 | - | |||||||||||||||||||
| 719 | /*! | - | ||||||||||||||||||
| 720 | Creates and returns a mask for this pixmap based on the given \a | - | ||||||||||||||||||
| 721 | maskColor. If the \a mode is Qt::MaskInColor, all pixels matching the | - | ||||||||||||||||||
| 722 | maskColor will be transparent. If \a mode is Qt::MaskOutColor, all pixels | - | ||||||||||||||||||
| 723 | matching the maskColor will be opaque. | - | ||||||||||||||||||
| 724 | - | |||||||||||||||||||
| 725 | This function is slow because it involves converting to/from a | - | ||||||||||||||||||
| 726 | QImage. | - | ||||||||||||||||||
| 727 | - | |||||||||||||||||||
| 728 | \sa createHeuristicMask(), QImage::createMaskFromColor() | - | ||||||||||||||||||
| 729 | */ | - | ||||||||||||||||||
| 730 | QBitmap QPixmap::createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const | - | ||||||||||||||||||
| 731 | { | - | ||||||||||||||||||
| 732 | QImage image = toImage().convertToFormat(QImage::Format_ARGB32); | - | ||||||||||||||||||
| 733 | return QBitmap::fromImage(image.createMaskFromColor(maskColor.rgba(), mode)); never executed: return QBitmap::fromImage(image.createMaskFromColor(maskColor.rgba(), mode)); | 0 | ||||||||||||||||||
| 734 | } | - | ||||||||||||||||||
| 735 | - | |||||||||||||||||||
| 736 | /*! | - | ||||||||||||||||||
| 737 | Loads a pixmap from the file with the given \a fileName. Returns | - | ||||||||||||||||||
| 738 | true if the pixmap was successfully loaded; otherwise invalidates | - | ||||||||||||||||||
| 739 | the pixmap and returns \c false. | - | ||||||||||||||||||
| 740 | - | |||||||||||||||||||
| 741 | The loader attempts to read the pixmap using the specified \a | - | ||||||||||||||||||
| 742 | format. If the \a format is not specified (which is the default), | - | ||||||||||||||||||
| 743 | the loader probes the file for a header to guess the file format. | - | ||||||||||||||||||
| 744 | - | |||||||||||||||||||
| 745 | The file name can either refer to an actual file on disk or to one | - | ||||||||||||||||||
| 746 | of the application's embedded resources. See the | - | ||||||||||||||||||
| 747 | \l{resources.html}{Resource System} overview for details on how to | - | ||||||||||||||||||
| 748 | embed pixmaps and other resource files in the application's | - | ||||||||||||||||||
| 749 | executable. | - | ||||||||||||||||||
| 750 | - | |||||||||||||||||||
| 751 | If the data needs to be modified to fit in a lower-resolution | - | ||||||||||||||||||
| 752 | result (e.g. converting from 32-bit to 8-bit), use the \a flags to | - | ||||||||||||||||||
| 753 | control the conversion. | - | ||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | Note that QPixmaps are automatically added to the QPixmapCache | - | ||||||||||||||||||
| 756 | when loaded from a file; the key used is internal and can not | - | ||||||||||||||||||
| 757 | be acquired. | - | ||||||||||||||||||
| 758 | - | |||||||||||||||||||
| 759 | \sa loadFromData(), {QPixmap#Reading and Writing Image | - | ||||||||||||||||||
| 760 | Files}{Reading and Writing Image Files} | - | ||||||||||||||||||
| 761 | */ | - | ||||||||||||||||||
| 762 | - | |||||||||||||||||||
| 763 | bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 764 | { | - | ||||||||||||||||||
| 765 | if (!fileName.isEmpty()) {
| 0 | ||||||||||||||||||
| 766 | - | |||||||||||||||||||
| 767 | QFileInfo info(fileName); | - | ||||||||||||||||||
| 768 | // Note: If no extension is provided, we try to match the | - | ||||||||||||||||||
| 769 | // file against known plugin extensions | - | ||||||||||||||||||
| 770 | if (info.completeSuffix().isEmpty() || info.exists()) {
| 0 | ||||||||||||||||||
| 771 | - | |||||||||||||||||||
| 772 | QString key = QLatin1String("qt_pixmap") | - | ||||||||||||||||||
| 773 | % info.absoluteFilePath() | - | ||||||||||||||||||
| 774 | % HexString<uint>(info.lastModified().toTime_t()) | - | ||||||||||||||||||
| 775 | % HexString<quint64>(info.size()) | - | ||||||||||||||||||
| 776 | % HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType); | - | ||||||||||||||||||
| 777 | - | |||||||||||||||||||
| 778 | if (QPixmapCache::find(key, this))
| 0 | ||||||||||||||||||
| 779 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 780 | - | |||||||||||||||||||
| 781 | data = QPlatformPixmap::create(0, 0, data ? data->pixelType() : QPlatformPixmap::PixmapType); | - | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | if (data->fromFile(fileName, format, flags)) {
| 0 | ||||||||||||||||||
| 784 | QPixmapCache::insert(key, *this); | - | ||||||||||||||||||
| 785 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 786 | } | - | ||||||||||||||||||
| 787 | } never executed: end of block | 0 | ||||||||||||||||||
| 788 | } never executed: end of block | 0 | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | if (!isNull()) {
| 0 | ||||||||||||||||||
| 791 | if (isQBitmap())
| 0 | ||||||||||||||||||
| 792 | *this = QBitmap(); never executed: *this = QBitmap(); | 0 | ||||||||||||||||||
| 793 | else | - | ||||||||||||||||||
| 794 | data.reset(); never executed: data.reset(); | 0 | ||||||||||||||||||
| 795 | } | - | ||||||||||||||||||
| 796 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 797 | } | - | ||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | /*! | - | ||||||||||||||||||
| 800 | \fn bool QPixmap::loadFromData(const uchar *data, uint len, const char *format, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 801 | - | |||||||||||||||||||
| 802 | Loads a pixmap from the \a len first bytes of the given binary \a | - | ||||||||||||||||||
| 803 | data. Returns \c true if the pixmap was loaded successfully; | - | ||||||||||||||||||
| 804 | otherwise invalidates the pixmap and returns \c false. | - | ||||||||||||||||||
| 805 | - | |||||||||||||||||||
| 806 | The loader attempts to read the pixmap using the specified \a | - | ||||||||||||||||||
| 807 | format. If the \a format is not specified (which is the default), | - | ||||||||||||||||||
| 808 | the loader probes the file for a header to guess the file format. | - | ||||||||||||||||||
| 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 | \sa load(), {QPixmap#Reading and Writing Image Files}{Reading and | - | ||||||||||||||||||
| 815 | Writing Image Files} | - | ||||||||||||||||||
| 816 | */ | - | ||||||||||||||||||
| 817 | - | |||||||||||||||||||
| 818 | bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 819 | { | - | ||||||||||||||||||
| 820 | if (len == 0 || buf == 0) {
| 0 | ||||||||||||||||||
| 821 | data.reset(); | - | ||||||||||||||||||
| 822 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 823 | } | - | ||||||||||||||||||
| 824 | - | |||||||||||||||||||
| 825 | data = QPlatformPixmap::create(0, 0, QPlatformPixmap::PixmapType); | - | ||||||||||||||||||
| 826 | - | |||||||||||||||||||
| 827 | if (data->fromData(buf, len, format, flags))
| 0 | ||||||||||||||||||
| 828 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 829 | - | |||||||||||||||||||
| 830 | data.reset(); | - | ||||||||||||||||||
| 831 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 832 | } | - | ||||||||||||||||||
| 833 | - | |||||||||||||||||||
| 834 | /*! | - | ||||||||||||||||||
| 835 | \fn bool QPixmap::loadFromData(const QByteArray &data, const char *format, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 836 | - | |||||||||||||||||||
| 837 | \overload | - | ||||||||||||||||||
| 838 | - | |||||||||||||||||||
| 839 | Loads a pixmap from the binary \a data using the specified \a | - | ||||||||||||||||||
| 840 | format and conversion \a flags. | - | ||||||||||||||||||
| 841 | */ | - | ||||||||||||||||||
| 842 | - | |||||||||||||||||||
| 843 | - | |||||||||||||||||||
| 844 | /*! | - | ||||||||||||||||||
| 845 | Saves the pixmap to the file with the given \a fileName using the | - | ||||||||||||||||||
| 846 | specified image file \a format and \a quality factor. Returns \c true | - | ||||||||||||||||||
| 847 | if successful; otherwise returns \c false. | - | ||||||||||||||||||
| 848 | - | |||||||||||||||||||
| 849 | The \a quality factor must be in the range [0,100] or -1. Specify | - | ||||||||||||||||||
| 850 | 0 to obtain small compressed files, 100 for large uncompressed | - | ||||||||||||||||||
| 851 | files, and -1 to use the default settings. | - | ||||||||||||||||||
| 852 | - | |||||||||||||||||||
| 853 | If \a format is 0, an image format will be chosen from \a fileName's | - | ||||||||||||||||||
| 854 | suffix. | - | ||||||||||||||||||
| 855 | - | |||||||||||||||||||
| 856 | \sa {QPixmap#Reading and Writing Image Files}{Reading and Writing | - | ||||||||||||||||||
| 857 | Image Files} | - | ||||||||||||||||||
| 858 | */ | - | ||||||||||||||||||
| 859 | - | |||||||||||||||||||
| 860 | bool QPixmap::save(const QString &fileName, const char *format, int quality) const | - | ||||||||||||||||||
| 861 | { | - | ||||||||||||||||||
| 862 | if (isNull())
| 0 | ||||||||||||||||||
| 863 | return false; // nothing to save never executed: return false; | 0 | ||||||||||||||||||
| 864 | QImageWriter writer(fileName, format); | - | ||||||||||||||||||
| 865 | return doImageIO(&writer, quality); never executed: return doImageIO(&writer, quality); | 0 | ||||||||||||||||||
| 866 | } | - | ||||||||||||||||||
| 867 | - | |||||||||||||||||||
| 868 | /*! | - | ||||||||||||||||||
| 869 | \overload | - | ||||||||||||||||||
| 870 | - | |||||||||||||||||||
| 871 | This function writes a QPixmap to the given \a device using the | - | ||||||||||||||||||
| 872 | specified image file \a format and \a quality factor. This can be | - | ||||||||||||||||||
| 873 | used, for example, to save a pixmap directly into a QByteArray: | - | ||||||||||||||||||
| 874 | - | |||||||||||||||||||
| 875 | \snippet image/image.cpp 1 | - | ||||||||||||||||||
| 876 | */ | - | ||||||||||||||||||
| 877 | - | |||||||||||||||||||
| 878 | bool QPixmap::save(QIODevice* device, const char* format, int quality) const | - | ||||||||||||||||||
| 879 | { | - | ||||||||||||||||||
| 880 | if (isNull())
| 0 | ||||||||||||||||||
| 881 | return false; // nothing to save never executed: return false; | 0 | ||||||||||||||||||
| 882 | QImageWriter writer(device, format); | - | ||||||||||||||||||
| 883 | return doImageIO(&writer, quality); never executed: return doImageIO(&writer, quality); | 0 | ||||||||||||||||||
| 884 | } | - | ||||||||||||||||||
| 885 | - | |||||||||||||||||||
| 886 | /*! \internal | - | ||||||||||||||||||
| 887 | */ | - | ||||||||||||||||||
| 888 | bool QPixmap::doImageIO(QImageWriter *writer, int quality) const | - | ||||||||||||||||||
| 889 | { | - | ||||||||||||||||||
| 890 | if (quality > 100 || quality < -1)
| 0 | ||||||||||||||||||
| 891 | qWarning("QPixmap::save: quality out of range [-1,100]"); never executed: QMessageLogger(__FILE__, 891, __PRETTY_FUNCTION__).warning("QPixmap::save: quality out of range [-1,100]"); | 0 | ||||||||||||||||||
| 892 | if (quality >= 0)
| 0 | ||||||||||||||||||
| 893 | writer->setQuality(qMin(quality,100)); never executed: writer->setQuality(qMin(quality,100)); | 0 | ||||||||||||||||||
| 894 | return writer->write(toImage()); never executed: return writer->write(toImage()); | 0 | ||||||||||||||||||
| 895 | } | - | ||||||||||||||||||
| 896 | - | |||||||||||||||||||
| 897 | - | |||||||||||||||||||
| 898 | /*! | - | ||||||||||||||||||
| 899 | \obsolete | - | ||||||||||||||||||
| 900 | - | |||||||||||||||||||
| 901 | Use QPainter or the fill(QColor) overload instead. | - | ||||||||||||||||||
| 902 | */ | - | ||||||||||||||||||
| 903 | - | |||||||||||||||||||
| 904 | void QPixmap::fill(const QPaintDevice *device, const QPoint &p) | - | ||||||||||||||||||
| 905 | { | - | ||||||||||||||||||
| 906 | Q_UNUSED(device) | - | ||||||||||||||||||
| 907 | Q_UNUSED(p) | - | ||||||||||||||||||
| 908 | qWarning("this function is deprecated, ignored"); | - | ||||||||||||||||||
| 909 | } never executed: end of block | 0 | ||||||||||||||||||
| 910 | - | |||||||||||||||||||
| 911 | - | |||||||||||||||||||
| 912 | /*! | - | ||||||||||||||||||
| 913 | \fn void QPixmap::fill(const QPaintDevice *device, int x, int y) | - | ||||||||||||||||||
| 914 | \obsolete | - | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | Use QPainter or the fill(QColor) overload instead. | - | ||||||||||||||||||
| 917 | */ | - | ||||||||||||||||||
| 918 | - | |||||||||||||||||||
| 919 | - | |||||||||||||||||||
| 920 | /*! | - | ||||||||||||||||||
| 921 | Fills the pixmap with the given \a color. | - | ||||||||||||||||||
| 922 | - | |||||||||||||||||||
| 923 | The effect of this function is undefined when the pixmap is | - | ||||||||||||||||||
| 924 | being painted on. | - | ||||||||||||||||||
| 925 | - | |||||||||||||||||||
| 926 | \sa {QPixmap#Pixmap Transformations}{Pixmap Transformations} | - | ||||||||||||||||||
| 927 | */ | - | ||||||||||||||||||
| 928 | - | |||||||||||||||||||
| 929 | void QPixmap::fill(const QColor &color) | - | ||||||||||||||||||
| 930 | { | - | ||||||||||||||||||
| 931 | if (isNull())
| 0 | ||||||||||||||||||
| 932 | return; never executed: return; | 0 | ||||||||||||||||||
| 933 | - | |||||||||||||||||||
| 934 | // Some people are probably already calling fill while a painter is active, so to not break | - | ||||||||||||||||||
| 935 | // their programs, only print a warning and return when the fill operation could cause a crash. | - | ||||||||||||||||||
| 936 | if (paintingActive() && (color.alpha() != 255) && !hasAlphaChannel()) {
| 0 | ||||||||||||||||||
| 937 | qWarning("QPixmap::fill: Cannot fill while pixmap is being painted on"); | - | ||||||||||||||||||
| 938 | return; never executed: return; | 0 | ||||||||||||||||||
| 939 | } | - | ||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | if (data->ref.load() == 1) {
| 0 | ||||||||||||||||||
| 942 | // detach() will also remove this pixmap from caches, so | - | ||||||||||||||||||
| 943 | // it has to be called even when ref == 1. | - | ||||||||||||||||||
| 944 | detach(); | - | ||||||||||||||||||
| 945 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 946 | // Don't bother to make a copy of the data object, since | - | ||||||||||||||||||
| 947 | // it will be filled with new pixel data anyway. | - | ||||||||||||||||||
| 948 | QPlatformPixmap *d = data->createCompatiblePlatformPixmap(); | - | ||||||||||||||||||
| 949 | d->resize(data->width(), data->height()); | - | ||||||||||||||||||
| 950 | data = d; | - | ||||||||||||||||||
| 951 | } never executed: end of block | 0 | ||||||||||||||||||
| 952 | data->fill(color); | - | ||||||||||||||||||
| 953 | } never executed: end of block | 0 | ||||||||||||||||||
| 954 | - | |||||||||||||||||||
| 955 | /*! \fn int QPixmap::serialNumber() const | - | ||||||||||||||||||
| 956 | \obsolete | - | ||||||||||||||||||
| 957 | Returns a number that identifies the contents of this QPixmap | - | ||||||||||||||||||
| 958 | object. Distinct QPixmap objects can only have the same serial | - | ||||||||||||||||||
| 959 | number if they refer to the same contents (but they don't have | - | ||||||||||||||||||
| 960 | to). | - | ||||||||||||||||||
| 961 | - | |||||||||||||||||||
| 962 | Use cacheKey() instead. | - | ||||||||||||||||||
| 963 | - | |||||||||||||||||||
| 964 | \warning The serial number doesn't necessarily change when | - | ||||||||||||||||||
| 965 | the pixmap is altered. This means that it may be dangerous to use | - | ||||||||||||||||||
| 966 | it as a cache key. For caching pixmaps, we recommend using the | - | ||||||||||||||||||
| 967 | QPixmapCache class whenever possible. | - | ||||||||||||||||||
| 968 | */ | - | ||||||||||||||||||
| 969 | - | |||||||||||||||||||
| 970 | /*! | - | ||||||||||||||||||
| 971 | Returns a number that identifies this QPixmap. Distinct QPixmap | - | ||||||||||||||||||
| 972 | objects can only have the same cache key if they refer to the same | - | ||||||||||||||||||
| 973 | contents. | - | ||||||||||||||||||
| 974 | - | |||||||||||||||||||
| 975 | The cacheKey() will change when the pixmap is altered. | - | ||||||||||||||||||
| 976 | */ | - | ||||||||||||||||||
| 977 | qint64 QPixmap::cacheKey() const | - | ||||||||||||||||||
| 978 | { | - | ||||||||||||||||||
| 979 | if (isNull())
| 0 | ||||||||||||||||||
| 980 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 981 | - | |||||||||||||||||||
| 982 | Q_ASSERT(data); | - | ||||||||||||||||||
| 983 | return data->cacheKey(); never executed: return data->cacheKey(); | 0 | ||||||||||||||||||
| 984 | } | - | ||||||||||||||||||
| 985 | - | |||||||||||||||||||
| 986 | #if 0 | - | ||||||||||||||||||
| 987 | static void sendResizeEvents(QWidget *target) | - | ||||||||||||||||||
| 988 | { | - | ||||||||||||||||||
| 989 | QResizeEvent e(target->size(), QSize()); | - | ||||||||||||||||||
| 990 | QApplication::sendEvent(target, &e); | - | ||||||||||||||||||
| 991 | - | |||||||||||||||||||
| 992 | const QObjectList children = target->children(); | - | ||||||||||||||||||
| 993 | for (int i = 0; i < children.size(); ++i) { | - | ||||||||||||||||||
| 994 | QWidget *child = static_cast<QWidget*>(children.at(i)); | - | ||||||||||||||||||
| 995 | if (child->isWidgetType() && !child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent)) | - | ||||||||||||||||||
| 996 | sendResizeEvents(child); | - | ||||||||||||||||||
| 997 | } | - | ||||||||||||||||||
| 998 | } | - | ||||||||||||||||||
| 999 | #endif | - | ||||||||||||||||||
| 1000 | - | |||||||||||||||||||
| 1001 | /*! | - | ||||||||||||||||||
| 1002 | \obsolete | - | ||||||||||||||||||
| 1003 | - | |||||||||||||||||||
| 1004 | Use QWidget::grab() instead. | - | ||||||||||||||||||
| 1005 | */ | - | ||||||||||||||||||
| 1006 | QPixmap QPixmap::grabWidget(QObject *widget, const QRect &rectangle) | - | ||||||||||||||||||
| 1007 | { | - | ||||||||||||||||||
| 1008 | QPixmap pixmap; | - | ||||||||||||||||||
| 1009 | qWarning("QPixmap::grabWidget is deprecated, use QWidget::grab() instead"); | - | ||||||||||||||||||
| 1010 | if (!widget)
| 0 | ||||||||||||||||||
| 1011 | return pixmap; never executed: return pixmap; | 0 | ||||||||||||||||||
| 1012 | QMetaObject::invokeMethod(widget, "grab", Qt::DirectConnection, | - | ||||||||||||||||||
| 1013 | Q_RETURN_ARG(QPixmap, pixmap), | - | ||||||||||||||||||
| 1014 | Q_ARG(QRect, rectangle)); | - | ||||||||||||||||||
| 1015 | return pixmap; never executed: return pixmap; | 0 | ||||||||||||||||||
| 1016 | } | - | ||||||||||||||||||
| 1017 | - | |||||||||||||||||||
| 1018 | /*! | - | ||||||||||||||||||
| 1019 | \fn QPixmap QPixmap::grabWidget(QObject *widget, int x, int y, int w, int h) | - | ||||||||||||||||||
| 1020 | \obsolete | - | ||||||||||||||||||
| 1021 | - | |||||||||||||||||||
| 1022 | Use QWidget::grab() instead. | - | ||||||||||||||||||
| 1023 | */ | - | ||||||||||||||||||
| 1024 | - | |||||||||||||||||||
| 1025 | /***************************************************************************** | - | ||||||||||||||||||
| 1026 | QPixmap stream functions | - | ||||||||||||||||||
| 1027 | *****************************************************************************/ | - | ||||||||||||||||||
| 1028 | #if !defined(QT_NO_DATASTREAM) | - | ||||||||||||||||||
| 1029 | /*! | - | ||||||||||||||||||
| 1030 | \relates QPixmap | - | ||||||||||||||||||
| 1031 | - | |||||||||||||||||||
| 1032 | Writes the given \a pixmap to the given \a stream as a PNG | - | ||||||||||||||||||
| 1033 | image. Note that writing the stream to a file will not produce a | - | ||||||||||||||||||
| 1034 | valid image file. | - | ||||||||||||||||||
| 1035 | - | |||||||||||||||||||
| 1036 | \sa QPixmap::save(), {Serializing Qt Data Types} | - | ||||||||||||||||||
| 1037 | */ | - | ||||||||||||||||||
| 1038 | - | |||||||||||||||||||
| 1039 | QDataStream &operator<<(QDataStream &stream, const QPixmap &pixmap) | - | ||||||||||||||||||
| 1040 | { | - | ||||||||||||||||||
| 1041 | return stream << pixmap.toImage(); never executed: return stream << pixmap.toImage(); | 0 | ||||||||||||||||||
| 1042 | } | - | ||||||||||||||||||
| 1043 | - | |||||||||||||||||||
| 1044 | /*! | - | ||||||||||||||||||
| 1045 | \relates QPixmap | - | ||||||||||||||||||
| 1046 | - | |||||||||||||||||||
| 1047 | Reads an image from the given \a stream into the given \a pixmap. | - | ||||||||||||||||||
| 1048 | - | |||||||||||||||||||
| 1049 | \sa QPixmap::load(), {Serializing Qt Data Types} | - | ||||||||||||||||||
| 1050 | */ | - | ||||||||||||||||||
| 1051 | - | |||||||||||||||||||
| 1052 | QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap) | - | ||||||||||||||||||
| 1053 | { | - | ||||||||||||||||||
| 1054 | QImage image; | - | ||||||||||||||||||
| 1055 | stream >> image; | - | ||||||||||||||||||
| 1056 | - | |||||||||||||||||||
| 1057 | if (image.isNull()) {
| 0 | ||||||||||||||||||
| 1058 | pixmap = QPixmap(); | - | ||||||||||||||||||
| 1059 | } else if (image.depth() == 1) { never executed: end of block
| 0 | ||||||||||||||||||
| 1060 | pixmap = QBitmap::fromImage(image); | - | ||||||||||||||||||
| 1061 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1062 | pixmap = QPixmap::fromImage(image); | - | ||||||||||||||||||
| 1063 | } never executed: end of block | 0 | ||||||||||||||||||
| 1064 | return stream; never executed: return stream; | 0 | ||||||||||||||||||
| 1065 | } | - | ||||||||||||||||||
| 1066 | - | |||||||||||||||||||
| 1067 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||
| 1068 | - | |||||||||||||||||||
| 1069 | /*! | - | ||||||||||||||||||
| 1070 | \internal | - | ||||||||||||||||||
| 1071 | */ | - | ||||||||||||||||||
| 1072 | - | |||||||||||||||||||
| 1073 | bool QPixmap::isDetached() const | - | ||||||||||||||||||
| 1074 | { | - | ||||||||||||||||||
| 1075 | return data && data->ref.load() == 1; never executed: return data && data->ref.load() == 1;
| 0 | ||||||||||||||||||
| 1076 | } | - | ||||||||||||||||||
| 1077 | - | |||||||||||||||||||
| 1078 | /*! | - | ||||||||||||||||||
| 1079 | Replaces this pixmap's data with the given \a image using the | - | ||||||||||||||||||
| 1080 | specified \a flags to control the conversion. The \a flags | - | ||||||||||||||||||
| 1081 | argument is a bitwise-OR of the \l{Qt::ImageConversionFlags}. | - | ||||||||||||||||||
| 1082 | Passing 0 for \a flags sets all the default options. Returns \c true | - | ||||||||||||||||||
| 1083 | if the result is that this pixmap is not null. | - | ||||||||||||||||||
| 1084 | - | |||||||||||||||||||
| 1085 | Note: this function was part of Qt 3 support in Qt 4.6 and earlier. | - | ||||||||||||||||||
| 1086 | It has been promoted to official API status in 4.7 to support updating | - | ||||||||||||||||||
| 1087 | the pixmap's image without creating a new QPixmap as fromImage() would. | - | ||||||||||||||||||
| 1088 | - | |||||||||||||||||||
| 1089 | \sa fromImage() | - | ||||||||||||||||||
| 1090 | \since 4.7 | - | ||||||||||||||||||
| 1091 | */ | - | ||||||||||||||||||
| 1092 | bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 1093 | { | - | ||||||||||||||||||
| 1094 | detach(); | - | ||||||||||||||||||
| 1095 | if (image.isNull() || !data)
| 0 | ||||||||||||||||||
| 1096 | *this = QPixmap::fromImage(image, flags); never executed: *this = QPixmap::fromImage(image, flags); | 0 | ||||||||||||||||||
| 1097 | else | - | ||||||||||||||||||
| 1098 | data->fromImage(image, flags); never executed: data->fromImage(image, flags); | 0 | ||||||||||||||||||
| 1099 | return !isNull(); never executed: return !isNull(); | 0 | ||||||||||||||||||
| 1100 | } | - | ||||||||||||||||||
| 1101 | - | |||||||||||||||||||
| 1102 | /*! | - | ||||||||||||||||||
| 1103 | \fn QPixmap QPixmap::scaled(int width, int height, | - | ||||||||||||||||||
| 1104 | Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode | - | ||||||||||||||||||
| 1105 | transformMode) const | - | ||||||||||||||||||
| 1106 | - | |||||||||||||||||||
| 1107 | \overload | - | ||||||||||||||||||
| 1108 | - | |||||||||||||||||||
| 1109 | Returns a copy of the pixmap scaled to a rectangle with the given | - | ||||||||||||||||||
| 1110 | \a width and \a height according to the given \a aspectRatioMode and | - | ||||||||||||||||||
| 1111 | \a transformMode. | - | ||||||||||||||||||
| 1112 | - | |||||||||||||||||||
| 1113 | If either the \a width or the \a height is zero or negative, this | - | ||||||||||||||||||
| 1114 | function returns a null pixmap. | - | ||||||||||||||||||
| 1115 | */ | - | ||||||||||||||||||
| 1116 | - | |||||||||||||||||||
| 1117 | /*! | - | ||||||||||||||||||
| 1118 | \fn QPixmap QPixmap::scaled(const QSize &size, Qt::AspectRatioMode | - | ||||||||||||||||||
| 1119 | aspectRatioMode, Qt::TransformationMode transformMode) const | - | ||||||||||||||||||
| 1120 | - | |||||||||||||||||||
| 1121 | Scales the pixmap to the given \a size, using the aspect ratio and | - | ||||||||||||||||||
| 1122 | transformation modes specified by \a aspectRatioMode and \a | - | ||||||||||||||||||
| 1123 | transformMode. | - | ||||||||||||||||||
| 1124 | - | |||||||||||||||||||
| 1125 | \image qimage-scaling.png | - | ||||||||||||||||||
| 1126 | - | |||||||||||||||||||
| 1127 | \list | - | ||||||||||||||||||
| 1128 | \li If \a aspectRatioMode is Qt::IgnoreAspectRatio, the pixmap | - | ||||||||||||||||||
| 1129 | is scaled to \a size. | - | ||||||||||||||||||
| 1130 | \li If \a aspectRatioMode is Qt::KeepAspectRatio, the pixmap is | - | ||||||||||||||||||
| 1131 | scaled to a rectangle as large as possible inside \a size, preserving the aspect ratio. | - | ||||||||||||||||||
| 1132 | \li If \a aspectRatioMode is Qt::KeepAspectRatioByExpanding, | - | ||||||||||||||||||
| 1133 | the pixmap is scaled to a rectangle as small as possible | - | ||||||||||||||||||
| 1134 | outside \a size, preserving the aspect ratio. | - | ||||||||||||||||||
| 1135 | \endlist | - | ||||||||||||||||||
| 1136 | - | |||||||||||||||||||
| 1137 | If the given \a size is empty, this function returns a null | - | ||||||||||||||||||
| 1138 | pixmap. | - | ||||||||||||||||||
| 1139 | - | |||||||||||||||||||
| 1140 | - | |||||||||||||||||||
| 1141 | In some cases it can be more beneficial to draw the pixmap to a | - | ||||||||||||||||||
| 1142 | painter with a scale set rather than scaling the pixmap. This is | - | ||||||||||||||||||
| 1143 | the case when the painter is for instance based on OpenGL or when | - | ||||||||||||||||||
| 1144 | the scale factor changes rapidly. | - | ||||||||||||||||||
| 1145 | - | |||||||||||||||||||
| 1146 | \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap | - | ||||||||||||||||||
| 1147 | Transformations} | - | ||||||||||||||||||
| 1148 | - | |||||||||||||||||||
| 1149 | */ | - | ||||||||||||||||||
| 1150 | QPixmap QPixmap::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const | - | ||||||||||||||||||
| 1151 | { | - | ||||||||||||||||||
| 1152 | if (isNull()) {
| 0 | ||||||||||||||||||
| 1153 | qWarning("QPixmap::scaled: Pixmap is a null pixmap"); | - | ||||||||||||||||||
| 1154 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||||||||
| 1155 | } | - | ||||||||||||||||||
| 1156 | if (s.isEmpty())
| 0 | ||||||||||||||||||
| 1157 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||||||||
| 1158 | - | |||||||||||||||||||
| 1159 | QSize newSize = size(); | - | ||||||||||||||||||
| 1160 | newSize.scale(s, aspectMode); | - | ||||||||||||||||||
| 1161 | newSize.rwidth() = qMax(newSize.width(), 1); | - | ||||||||||||||||||
| 1162 | newSize.rheight() = qMax(newSize.height(), 1); | - | ||||||||||||||||||
| 1163 | if (newSize == size())
| 0 | ||||||||||||||||||
| 1164 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 1165 | - | |||||||||||||||||||
| 1166 | QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), | - | ||||||||||||||||||
| 1167 | (qreal)newSize.height() / height()); | - | ||||||||||||||||||
| 1168 | QPixmap pix = transformed(wm, mode); | - | ||||||||||||||||||
| 1169 | return pix; never executed: return pix; | 0 | ||||||||||||||||||
| 1170 | } | - | ||||||||||||||||||
| 1171 | - | |||||||||||||||||||
| 1172 | /*! | - | ||||||||||||||||||
| 1173 | \fn QPixmap QPixmap::scaledToWidth(int width, Qt::TransformationMode | - | ||||||||||||||||||
| 1174 | mode) const | - | ||||||||||||||||||
| 1175 | - | |||||||||||||||||||
| 1176 | Returns a scaled copy of the image. The returned image is scaled | - | ||||||||||||||||||
| 1177 | to the given \a width using the specified transformation \a mode. | - | ||||||||||||||||||
| 1178 | The height of the pixmap is automatically calculated so that the | - | ||||||||||||||||||
| 1179 | aspect ratio of the pixmap is preserved. | - | ||||||||||||||||||
| 1180 | - | |||||||||||||||||||
| 1181 | If \a width is 0 or negative, a null pixmap is returned. | - | ||||||||||||||||||
| 1182 | - | |||||||||||||||||||
| 1183 | \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap | - | ||||||||||||||||||
| 1184 | Transformations} | - | ||||||||||||||||||
| 1185 | */ | - | ||||||||||||||||||
| 1186 | QPixmap QPixmap::scaledToWidth(int w, Qt::TransformationMode mode) const | - | ||||||||||||||||||
| 1187 | { | - | ||||||||||||||||||
| 1188 | if (isNull()) {
| 0 | ||||||||||||||||||
| 1189 | qWarning("QPixmap::scaleWidth: Pixmap is a null pixmap"); | - | ||||||||||||||||||
| 1190 | return copy(); never executed: return copy(); | 0 | ||||||||||||||||||
| 1191 | } | - | ||||||||||||||||||
| 1192 | if (w <= 0)
| 0 | ||||||||||||||||||
| 1193 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||||||||
| 1194 | - | |||||||||||||||||||
| 1195 | qreal factor = (qreal) w / width(); | - | ||||||||||||||||||
| 1196 | QTransform wm = QTransform::fromScale(factor, factor); | - | ||||||||||||||||||
| 1197 | return transformed(wm, mode); never executed: return transformed(wm, mode); | 0 | ||||||||||||||||||
| 1198 | } | - | ||||||||||||||||||
| 1199 | - | |||||||||||||||||||
| 1200 | /*! | - | ||||||||||||||||||
| 1201 | \fn QPixmap QPixmap::scaledToHeight(int height, | - | ||||||||||||||||||
| 1202 | Qt::TransformationMode mode) const | - | ||||||||||||||||||
| 1203 | - | |||||||||||||||||||
| 1204 | Returns a scaled copy of the image. The returned image is scaled | - | ||||||||||||||||||
| 1205 | to the given \a height using the specified transformation \a mode. | - | ||||||||||||||||||
| 1206 | The width of the pixmap is automatically calculated so that the | - | ||||||||||||||||||
| 1207 | aspect ratio of the pixmap is preserved. | - | ||||||||||||||||||
| 1208 | - | |||||||||||||||||||
| 1209 | If \a height is 0 or negative, a null pixmap is returned. | - | ||||||||||||||||||
| 1210 | - | |||||||||||||||||||
| 1211 | \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap | - | ||||||||||||||||||
| 1212 | Transformations} | - | ||||||||||||||||||
| 1213 | */ | - | ||||||||||||||||||
| 1214 | QPixmap QPixmap::scaledToHeight(int h, Qt::TransformationMode mode) const | - | ||||||||||||||||||
| 1215 | { | - | ||||||||||||||||||
| 1216 | if (isNull()) {
| 0 | ||||||||||||||||||
| 1217 | qWarning("QPixmap::scaleHeight: Pixmap is a null pixmap"); | - | ||||||||||||||||||
| 1218 | return copy(); never executed: return copy(); | 0 | ||||||||||||||||||
| 1219 | } | - | ||||||||||||||||||
| 1220 | if (h <= 0)
| 0 | ||||||||||||||||||
| 1221 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||||||||
| 1222 | - | |||||||||||||||||||
| 1223 | qreal factor = (qreal) h / height(); | - | ||||||||||||||||||
| 1224 | QTransform wm = QTransform::fromScale(factor, factor); | - | ||||||||||||||||||
| 1225 | return transformed(wm, mode); never executed: return transformed(wm, mode); | 0 | ||||||||||||||||||
| 1226 | } | - | ||||||||||||||||||
| 1227 | - | |||||||||||||||||||
| 1228 | /*! | - | ||||||||||||||||||
| 1229 | Returns a copy of the pixmap that is transformed using the given | - | ||||||||||||||||||
| 1230 | transformation \a transform and transformation \a mode. The original | - | ||||||||||||||||||
| 1231 | pixmap is not changed. | - | ||||||||||||||||||
| 1232 | - | |||||||||||||||||||
| 1233 | The transformation \a transform is internally adjusted to compensate | - | ||||||||||||||||||
| 1234 | for unwanted translation; i.e. the pixmap produced is the smallest | - | ||||||||||||||||||
| 1235 | pixmap that contains all the transformed points of the original | - | ||||||||||||||||||
| 1236 | pixmap. Use the trueMatrix() function to retrieve the actual | - | ||||||||||||||||||
| 1237 | matrix used for transforming the pixmap. | - | ||||||||||||||||||
| 1238 | - | |||||||||||||||||||
| 1239 | This function is slow because it involves transformation to a | - | ||||||||||||||||||
| 1240 | QImage, non-trivial computations and a transformation back to a | - | ||||||||||||||||||
| 1241 | QPixmap. | - | ||||||||||||||||||
| 1242 | - | |||||||||||||||||||
| 1243 | \sa trueMatrix(), {QPixmap#Pixmap Transformations}{Pixmap | - | ||||||||||||||||||
| 1244 | Transformations} | - | ||||||||||||||||||
| 1245 | */ | - | ||||||||||||||||||
| 1246 | QPixmap QPixmap::transformed(const QTransform &transform, | - | ||||||||||||||||||
| 1247 | Qt::TransformationMode mode) const | - | ||||||||||||||||||
| 1248 | { | - | ||||||||||||||||||
| 1249 | if (isNull() || transform.type() <= QTransform::TxTranslate)
| 0 | ||||||||||||||||||
| 1250 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 1251 | - | |||||||||||||||||||
| 1252 | return data->transformed(transform, mode); never executed: return data->transformed(transform, mode); | 0 | ||||||||||||||||||
| 1253 | } | - | ||||||||||||||||||
| 1254 | - | |||||||||||||||||||
| 1255 | /*! | - | ||||||||||||||||||
| 1256 | \overload | - | ||||||||||||||||||
| 1257 | - | |||||||||||||||||||
| 1258 | This convenience function loads the \a matrix into a | - | ||||||||||||||||||
| 1259 | QTransform and calls the overloaded function. | - | ||||||||||||||||||
| 1260 | */ | - | ||||||||||||||||||
| 1261 | QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) const | - | ||||||||||||||||||
| 1262 | { | - | ||||||||||||||||||
| 1263 | return transformed(QTransform(matrix), mode); never executed: return transformed(QTransform(matrix), mode); | 0 | ||||||||||||||||||
| 1264 | } | - | ||||||||||||||||||
| 1265 | - | |||||||||||||||||||
| 1266 | - | |||||||||||||||||||
| 1267 | - | |||||||||||||||||||
| 1268 | - | |||||||||||||||||||
| 1269 | - | |||||||||||||||||||
| 1270 | - | |||||||||||||||||||
| 1271 | - | |||||||||||||||||||
| 1272 | - | |||||||||||||||||||
| 1273 | /*! | - | ||||||||||||||||||
| 1274 | \class QPixmap | - | ||||||||||||||||||
| 1275 | \inmodule QtGui | - | ||||||||||||||||||
| 1276 | - | |||||||||||||||||||
| 1277 | \brief The QPixmap class is an off-screen image representation | - | ||||||||||||||||||
| 1278 | that can be used as a paint device. | - | ||||||||||||||||||
| 1279 | - | |||||||||||||||||||
| 1280 | \ingroup painting | - | ||||||||||||||||||
| 1281 | \ingroup shared | - | ||||||||||||||||||
| 1282 | - | |||||||||||||||||||
| 1283 | - | |||||||||||||||||||
| 1284 | Qt provides four classes for handling image data: QImage, QPixmap, | - | ||||||||||||||||||
| 1285 | QBitmap and QPicture. QImage is designed and optimized for I/O, | - | ||||||||||||||||||
| 1286 | and for direct pixel access and manipulation, while QPixmap is | - | ||||||||||||||||||
| 1287 | designed and optimized for showing images on screen. QBitmap is | - | ||||||||||||||||||
| 1288 | only a convenience class that inherits QPixmap, ensuring a depth | - | ||||||||||||||||||
| 1289 | of 1. The isQBitmap() function returns \c true if a QPixmap object is | - | ||||||||||||||||||
| 1290 | really a bitmap, otherwise returns \c false. Finally, the QPicture class | - | ||||||||||||||||||
| 1291 | is a paint device that records and replays QPainter commands. | - | ||||||||||||||||||
| 1292 | - | |||||||||||||||||||
| 1293 | A QPixmap can easily be displayed on the screen using QLabel or | - | ||||||||||||||||||
| 1294 | one of QAbstractButton's subclasses (such as QPushButton and | - | ||||||||||||||||||
| 1295 | QToolButton). QLabel has a pixmap property, whereas | - | ||||||||||||||||||
| 1296 | QAbstractButton has an icon property. | - | ||||||||||||||||||
| 1297 | - | |||||||||||||||||||
| 1298 | QPixmap objects can be passed around by value since the QPixmap | - | ||||||||||||||||||
| 1299 | class uses implicit data sharing. For more information, see the \l | - | ||||||||||||||||||
| 1300 | {Implicit Data Sharing} documentation. QPixmap objects can also be | - | ||||||||||||||||||
| 1301 | streamed. | - | ||||||||||||||||||
| 1302 | - | |||||||||||||||||||
| 1303 | Note that the pixel data in a pixmap is internal and is managed by | - | ||||||||||||||||||
| 1304 | the underlying window system. Because QPixmap is a QPaintDevice | - | ||||||||||||||||||
| 1305 | subclass, QPainter can be used to draw directly onto pixmaps. | - | ||||||||||||||||||
| 1306 | Pixels can only be accessed through QPainter functions or by | - | ||||||||||||||||||
| 1307 | converting the QPixmap to a QImage. However, the fill() function | - | ||||||||||||||||||
| 1308 | is available for initializing the entire pixmap with a given color. | - | ||||||||||||||||||
| 1309 | - | |||||||||||||||||||
| 1310 | There are functions to convert between QImage and | - | ||||||||||||||||||
| 1311 | QPixmap. Typically, the QImage class is used to load an image | - | ||||||||||||||||||
| 1312 | file, optionally manipulating the image data, before the QImage | - | ||||||||||||||||||
| 1313 | object is converted into a QPixmap to be shown on | - | ||||||||||||||||||
| 1314 | screen. Alternatively, if no manipulation is desired, the image | - | ||||||||||||||||||
| 1315 | file can be loaded directly into a QPixmap. | - | ||||||||||||||||||
| 1316 | - | |||||||||||||||||||
| 1317 | QPixmap provides a collection of functions that can be used to | - | ||||||||||||||||||
| 1318 | obtain a variety of information about the pixmap. In addition, | - | ||||||||||||||||||
| 1319 | there are several functions that enables transformation of the | - | ||||||||||||||||||
| 1320 | pixmap. | - | ||||||||||||||||||
| 1321 | - | |||||||||||||||||||
| 1322 | \tableofcontents | - | ||||||||||||||||||
| 1323 | - | |||||||||||||||||||
| 1324 | \section1 Reading and Writing Image Files | - | ||||||||||||||||||
| 1325 | - | |||||||||||||||||||
| 1326 | QPixmap provides several ways of reading an image file: The file | - | ||||||||||||||||||
| 1327 | can be loaded when constructing the QPixmap object, or by using | - | ||||||||||||||||||
| 1328 | the load() or loadFromData() functions later on. When loading an | - | ||||||||||||||||||
| 1329 | image, the file name can either refer to an actual file on disk or | - | ||||||||||||||||||
| 1330 | to one of the application's embedded resources. See \l{The Qt | - | ||||||||||||||||||
| 1331 | Resource System} overview for details on how to embed images and | - | ||||||||||||||||||
| 1332 | other resource files in the application's executable. | - | ||||||||||||||||||
| 1333 | - | |||||||||||||||||||
| 1334 | Simply call the save() function to save a QPixmap object. | - | ||||||||||||||||||
| 1335 | - | |||||||||||||||||||
| 1336 | The complete list of supported file formats are available through | - | ||||||||||||||||||
| 1337 | the QImageReader::supportedImageFormats() and | - | ||||||||||||||||||
| 1338 | QImageWriter::supportedImageFormats() functions. New file formats | - | ||||||||||||||||||
| 1339 | can be added as plugins. By default, Qt supports the following | - | ||||||||||||||||||
| 1340 | formats: | - | ||||||||||||||||||
| 1341 | - | |||||||||||||||||||
| 1342 | \table | - | ||||||||||||||||||
| 1343 | \header \li Format \li Description \li Qt's support | - | ||||||||||||||||||
| 1344 | \row \li BMP \li Windows Bitmap \li Read/write | - | ||||||||||||||||||
| 1345 | \row \li GIF \li Graphic Interchange Format (optional) \li Read | - | ||||||||||||||||||
| 1346 | \row \li JPG \li Joint Photographic Experts Group \li Read/write | - | ||||||||||||||||||
| 1347 | \row \li JPEG \li Joint Photographic Experts Group \li Read/write | - | ||||||||||||||||||
| 1348 | \row \li PNG \li Portable Network Graphics \li Read/write | - | ||||||||||||||||||
| 1349 | \row \li PBM \li Portable Bitmap \li Read | - | ||||||||||||||||||
| 1350 | \row \li PGM \li Portable Graymap \li Read | - | ||||||||||||||||||
| 1351 | \row \li PPM \li Portable Pixmap \li Read/write | - | ||||||||||||||||||
| 1352 | \row \li XBM \li X11 Bitmap \li Read/write | - | ||||||||||||||||||
| 1353 | \row \li XPM \li X11 Pixmap \li Read/write | - | ||||||||||||||||||
| 1354 | \endtable | - | ||||||||||||||||||
| 1355 | - | |||||||||||||||||||
| 1356 | \section1 Pixmap Information | - | ||||||||||||||||||
| 1357 | - | |||||||||||||||||||
| 1358 | QPixmap provides a collection of functions that can be used to | - | ||||||||||||||||||
| 1359 | obtain a variety of information about the pixmap: | - | ||||||||||||||||||
| 1360 | - | |||||||||||||||||||
| 1361 | \table | - | ||||||||||||||||||
| 1362 | \header | - | ||||||||||||||||||
| 1363 | \li \li Available Functions | - | ||||||||||||||||||
| 1364 | \row | - | ||||||||||||||||||
| 1365 | \li Geometry | - | ||||||||||||||||||
| 1366 | \li | - | ||||||||||||||||||
| 1367 | The size(), width() and height() functions provide information | - | ||||||||||||||||||
| 1368 | about the pixmap's size. The rect() function returns the image's | - | ||||||||||||||||||
| 1369 | enclosing rectangle. | - | ||||||||||||||||||
| 1370 | - | |||||||||||||||||||
| 1371 | \row | - | ||||||||||||||||||
| 1372 | \li Alpha component | - | ||||||||||||||||||
| 1373 | \li | - | ||||||||||||||||||
| 1374 | - | |||||||||||||||||||
| 1375 | The hasAlphaChannel() returns \c true if the pixmap has a format that | - | ||||||||||||||||||
| 1376 | respects the alpha channel, otherwise returns \c false. The hasAlpha(), | - | ||||||||||||||||||
| 1377 | setMask() and mask() functions are legacy and should not be used. | - | ||||||||||||||||||
| 1378 | They are potentially very slow. | - | ||||||||||||||||||
| 1379 | - | |||||||||||||||||||
| 1380 | The createHeuristicMask() function creates and returns a 1-bpp | - | ||||||||||||||||||
| 1381 | heuristic mask (i.e. a QBitmap) for this pixmap. It works by | - | ||||||||||||||||||
| 1382 | selecting a color from one of the corners and then chipping away | - | ||||||||||||||||||
| 1383 | pixels of that color, starting at all the edges. The | - | ||||||||||||||||||
| 1384 | createMaskFromColor() function creates and returns a mask (i.e. a | - | ||||||||||||||||||
| 1385 | QBitmap) for the pixmap based on a given color. | - | ||||||||||||||||||
| 1386 | - | |||||||||||||||||||
| 1387 | \row | - | ||||||||||||||||||
| 1388 | \li Low-level information | - | ||||||||||||||||||
| 1389 | \li | - | ||||||||||||||||||
| 1390 | - | |||||||||||||||||||
| 1391 | The depth() function returns the depth of the pixmap. The | - | ||||||||||||||||||
| 1392 | defaultDepth() function returns the default depth, i.e. the depth | - | ||||||||||||||||||
| 1393 | used by the application on the given screen. | - | ||||||||||||||||||
| 1394 | - | |||||||||||||||||||
| 1395 | The cacheKey() function returns a number that uniquely | - | ||||||||||||||||||
| 1396 | identifies the contents of the QPixmap object. | - | ||||||||||||||||||
| 1397 | - | |||||||||||||||||||
| 1398 | The x11Info() function returns information about the configuration | - | ||||||||||||||||||
| 1399 | of the X display used by the screen to which the pixmap currently | - | ||||||||||||||||||
| 1400 | belongs. The x11PictureHandle() function returns the X11 Picture | - | ||||||||||||||||||
| 1401 | handle of the pixmap for XRender support. Note that the two latter | - | ||||||||||||||||||
| 1402 | functions are only available on x11. | - | ||||||||||||||||||
| 1403 | - | |||||||||||||||||||
| 1404 | \endtable | - | ||||||||||||||||||
| 1405 | - | |||||||||||||||||||
| 1406 | \section1 Pixmap Conversion | - | ||||||||||||||||||
| 1407 | - | |||||||||||||||||||
| 1408 | A QPixmap object can be converted into a QImage using the | - | ||||||||||||||||||
| 1409 | toImage() function. Likewise, a QImage can be converted into a | - | ||||||||||||||||||
| 1410 | QPixmap using the fromImage(). If this is too expensive an | - | ||||||||||||||||||
| 1411 | operation, you can use QBitmap::fromImage() instead. | - | ||||||||||||||||||
| 1412 | - | |||||||||||||||||||
| 1413 | To convert a QPixmap to and from HICON you can use the QtWinExtras | - | ||||||||||||||||||
| 1414 | functions QtWin::toHICON() and QtWin::fromHICON() respectively. | - | ||||||||||||||||||
| 1415 | - | |||||||||||||||||||
| 1416 | \section1 Pixmap Transformations | - | ||||||||||||||||||
| 1417 | - | |||||||||||||||||||
| 1418 | QPixmap supports a number of functions for creating a new pixmap | - | ||||||||||||||||||
| 1419 | that is a transformed version of the original: | - | ||||||||||||||||||
| 1420 | - | |||||||||||||||||||
| 1421 | The scaled(), scaledToWidth() and scaledToHeight() functions | - | ||||||||||||||||||
| 1422 | return scaled copies of the pixmap, while the copy() function | - | ||||||||||||||||||
| 1423 | creates a QPixmap that is a plain copy of the original one. | - | ||||||||||||||||||
| 1424 | - | |||||||||||||||||||
| 1425 | The transformed() function returns a copy of the pixmap that is | - | ||||||||||||||||||
| 1426 | transformed with the given transformation matrix and | - | ||||||||||||||||||
| 1427 | transformation mode: Internally, the transformation matrix is | - | ||||||||||||||||||
| 1428 | adjusted to compensate for unwanted translation, | - | ||||||||||||||||||
| 1429 | i.e. transformed() returns the smallest pixmap containing all | - | ||||||||||||||||||
| 1430 | transformed points of the original pixmap. The static trueMatrix() | - | ||||||||||||||||||
| 1431 | function returns the actual matrix used for transforming the | - | ||||||||||||||||||
| 1432 | pixmap. | - | ||||||||||||||||||
| 1433 | - | |||||||||||||||||||
| 1434 | \note When using the native X11 graphics system, the pixmap | - | ||||||||||||||||||
| 1435 | becomes invalid when the QApplication instance is destroyed. | - | ||||||||||||||||||
| 1436 | - | |||||||||||||||||||
| 1437 | \sa QBitmap, QImage, QImageReader, QImageWriter | - | ||||||||||||||||||
| 1438 | */ | - | ||||||||||||||||||
| 1439 | - | |||||||||||||||||||
| 1440 | - | |||||||||||||||||||
| 1441 | /*! | - | ||||||||||||||||||
| 1442 | \typedef QPixmap::DataPtr | - | ||||||||||||||||||
| 1443 | \internal | - | ||||||||||||||||||
| 1444 | */ | - | ||||||||||||||||||
| 1445 | - | |||||||||||||||||||
| 1446 | /*! | - | ||||||||||||||||||
| 1447 | \fn DataPtr &QPixmap::data_ptr() | - | ||||||||||||||||||
| 1448 | \internal | - | ||||||||||||||||||
| 1449 | */ | - | ||||||||||||||||||
| 1450 | - | |||||||||||||||||||
| 1451 | /*! | - | ||||||||||||||||||
| 1452 | Returns \c true if this pixmap has an alpha channel, \e or has a | - | ||||||||||||||||||
| 1453 | mask, otherwise returns \c false. | - | ||||||||||||||||||
| 1454 | - | |||||||||||||||||||
| 1455 | \sa hasAlphaChannel(), mask() | - | ||||||||||||||||||
| 1456 | */ | - | ||||||||||||||||||
| 1457 | bool QPixmap::hasAlpha() const | - | ||||||||||||||||||
| 1458 | { | - | ||||||||||||||||||
| 1459 | return data && data->hasAlphaChannel(); never executed: return data && data->hasAlphaChannel();
| 0 | ||||||||||||||||||
| 1460 | } | - | ||||||||||||||||||
| 1461 | - | |||||||||||||||||||
| 1462 | /*! | - | ||||||||||||||||||
| 1463 | Returns \c true if the pixmap has a format that respects the alpha | - | ||||||||||||||||||
| 1464 | channel, otherwise returns \c false. | - | ||||||||||||||||||
| 1465 | - | |||||||||||||||||||
| 1466 | \sa hasAlpha() | - | ||||||||||||||||||
| 1467 | */ | - | ||||||||||||||||||
| 1468 | bool QPixmap::hasAlphaChannel() const | - | ||||||||||||||||||
| 1469 | { | - | ||||||||||||||||||
| 1470 | return data && data->hasAlphaChannel(); never executed: return data && data->hasAlphaChannel();
| 0 | ||||||||||||||||||
| 1471 | } | - | ||||||||||||||||||
| 1472 | - | |||||||||||||||||||
| 1473 | /*! | - | ||||||||||||||||||
| 1474 | \internal | - | ||||||||||||||||||
| 1475 | */ | - | ||||||||||||||||||
| 1476 | int QPixmap::metric(PaintDeviceMetric metric) const | - | ||||||||||||||||||
| 1477 | { | - | ||||||||||||||||||
| 1478 | return data ? data->metric(metric) : 0; never executed: return data ? data->metric(metric) : 0;
| 0 | ||||||||||||||||||
| 1479 | } | - | ||||||||||||||||||
| 1480 | - | |||||||||||||||||||
| 1481 | /*! | - | ||||||||||||||||||
| 1482 | \internal | - | ||||||||||||||||||
| 1483 | */ | - | ||||||||||||||||||
| 1484 | QPaintEngine *QPixmap::paintEngine() const | - | ||||||||||||||||||
| 1485 | { | - | ||||||||||||||||||
| 1486 | return data ? data->paintEngine() : 0; never executed: return data ? data->paintEngine() : 0;
| 0 | ||||||||||||||||||
| 1487 | } | - | ||||||||||||||||||
| 1488 | - | |||||||||||||||||||
| 1489 | /*! | - | ||||||||||||||||||
| 1490 | \fn QBitmap QPixmap::mask() const | - | ||||||||||||||||||
| 1491 | - | |||||||||||||||||||
| 1492 | Extracts a bitmap mask from the pixmap's alpha channel. | - | ||||||||||||||||||
| 1493 | - | |||||||||||||||||||
| 1494 | \warning This is potentially an expensive operation. The mask of | - | ||||||||||||||||||
| 1495 | the pixmap is extracted dynamically from the pixeldata. | - | ||||||||||||||||||
| 1496 | - | |||||||||||||||||||
| 1497 | \sa setMask(), {QPixmap#Pixmap Information}{Pixmap Information} | - | ||||||||||||||||||
| 1498 | */ | - | ||||||||||||||||||
| 1499 | QBitmap QPixmap::mask() const | - | ||||||||||||||||||
| 1500 | { | - | ||||||||||||||||||
| 1501 | if (!data || !hasAlphaChannel())
| 0 | ||||||||||||||||||
| 1502 | return QBitmap(); never executed: return QBitmap(); | 0 | ||||||||||||||||||
| 1503 | - | |||||||||||||||||||
| 1504 | const QImage img = toImage(); | - | ||||||||||||||||||
| 1505 | bool shouldConvert = (img.format() != QImage::Format_ARGB32 && img.format() != QImage::Format_ARGB32_Premultiplied);
| 0 | ||||||||||||||||||
| 1506 | const QImage image = (shouldConvert ? img.convertToFormat(QImage::Format_ARGB32_Premultiplied) : img);
| 0 | ||||||||||||||||||
| 1507 | const int w = image.width(); | - | ||||||||||||||||||
| 1508 | const int h = image.height(); | - | ||||||||||||||||||
| 1509 | - | |||||||||||||||||||
| 1510 | QImage mask(w, h, QImage::Format_MonoLSB); | - | ||||||||||||||||||
| 1511 | if (mask.isNull()) // allocation failed
| 0 | ||||||||||||||||||
| 1512 | return QBitmap(); never executed: return QBitmap(); | 0 | ||||||||||||||||||
| 1513 | - | |||||||||||||||||||
| 1514 | mask.setColorCount(2); | - | ||||||||||||||||||
| 1515 | mask.setColor(0, QColor(Qt::color0).rgba()); | - | ||||||||||||||||||
| 1516 | mask.setColor(1, QColor(Qt::color1).rgba()); | - | ||||||||||||||||||
| 1517 | - | |||||||||||||||||||
| 1518 | const int bpl = mask.bytesPerLine(); | - | ||||||||||||||||||
| 1519 | - | |||||||||||||||||||
| 1520 | for (int y = 0; y < h; ++y) {
| 0 | ||||||||||||||||||
| 1521 | const QRgb *src = reinterpret_cast<const QRgb*>(image.scanLine(y)); | - | ||||||||||||||||||
| 1522 | uchar *dest = mask.scanLine(y); | - | ||||||||||||||||||
| 1523 | memset(dest, 0, bpl); | - | ||||||||||||||||||
| 1524 | for (int x = 0; x < w; ++x) {
| 0 | ||||||||||||||||||
| 1525 | if (qAlpha(*src) > 0)
| 0 | ||||||||||||||||||
| 1526 | dest[x >> 3] |= (1 << (x & 7)); never executed: dest[x >> 3] |= (1 << (x & 7)); | 0 | ||||||||||||||||||
| 1527 | ++src; | - | ||||||||||||||||||
| 1528 | } never executed: end of block | 0 | ||||||||||||||||||
| 1529 | } never executed: end of block | 0 | ||||||||||||||||||
| 1530 | - | |||||||||||||||||||
| 1531 | return QBitmap::fromImage(mask); never executed: return QBitmap::fromImage(mask); | 0 | ||||||||||||||||||
| 1532 | } | - | ||||||||||||||||||
| 1533 | - | |||||||||||||||||||
| 1534 | /*! | - | ||||||||||||||||||
| 1535 | Returns the default pixmap depth used by the application. | - | ||||||||||||||||||
| 1536 | - | |||||||||||||||||||
| 1537 | On all platforms the depth of the primary screen will be returned. | - | ||||||||||||||||||
| 1538 | - | |||||||||||||||||||
| 1539 | \sa depth(), QColormap::depth(), {QPixmap#Pixmap Information}{Pixmap Information} | - | ||||||||||||||||||
| 1540 | - | |||||||||||||||||||
| 1541 | */ | - | ||||||||||||||||||
| 1542 | int QPixmap::defaultDepth() | - | ||||||||||||||||||
| 1543 | { | - | ||||||||||||||||||
| 1544 | return QGuiApplication::primaryScreen()->depth(); never executed: return QGuiApplication::primaryScreen()->depth(); | 0 | ||||||||||||||||||
| 1545 | } | - | ||||||||||||||||||
| 1546 | - | |||||||||||||||||||
| 1547 | /*! | - | ||||||||||||||||||
| 1548 | Detaches the pixmap from shared pixmap data. | - | ||||||||||||||||||
| 1549 | - | |||||||||||||||||||
| 1550 | A pixmap is automatically detached by Qt whenever its contents are | - | ||||||||||||||||||
| 1551 | about to change. This is done in almost all QPixmap member | - | ||||||||||||||||||
| 1552 | functions that modify the pixmap (fill(), fromImage(), | - | ||||||||||||||||||
| 1553 | load(), etc.), and in QPainter::begin() on a pixmap. | - | ||||||||||||||||||
| 1554 | - | |||||||||||||||||||
| 1555 | There are two exceptions in which detach() must be called | - | ||||||||||||||||||
| 1556 | explicitly, that is when calling the handle() or the | - | ||||||||||||||||||
| 1557 | x11PictureHandle() function (only available on X11). Otherwise, | - | ||||||||||||||||||
| 1558 | any modifications done using system calls, will be performed on | - | ||||||||||||||||||
| 1559 | the shared data. | - | ||||||||||||||||||
| 1560 | - | |||||||||||||||||||
| 1561 | The detach() function returns immediately if there is just a | - | ||||||||||||||||||
| 1562 | single reference or if the pixmap has not been initialized yet. | - | ||||||||||||||||||
| 1563 | */ | - | ||||||||||||||||||
| 1564 | void QPixmap::detach() | - | ||||||||||||||||||
| 1565 | { | - | ||||||||||||||||||
| 1566 | if (!data)
| 0 | ||||||||||||||||||
| 1567 | return; never executed: return; | 0 | ||||||||||||||||||
| 1568 | - | |||||||||||||||||||
| 1569 | // QPixmap.data member may be QRuntimePlatformPixmap so use handle() function to get | - | ||||||||||||||||||
| 1570 | // the actual underlaying runtime pixmap data. | - | ||||||||||||||||||
| 1571 | QPlatformPixmap *pd = handle(); | - | ||||||||||||||||||
| 1572 | QPlatformPixmap::ClassId id = pd->classId(); | - | ||||||||||||||||||
| 1573 | if (id == QPlatformPixmap::RasterClass) {
| 0 | ||||||||||||||||||
| 1574 | QRasterPlatformPixmap *rasterData = static_cast<QRasterPlatformPixmap*>(pd); | - | ||||||||||||||||||
| 1575 | rasterData->image.detach(); | - | ||||||||||||||||||
| 1576 | } never executed: end of block | 0 | ||||||||||||||||||
| 1577 | - | |||||||||||||||||||
| 1578 | if (data->is_cached && data->ref.load() == 1)
| 0 | ||||||||||||||||||
| 1579 | QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(data.data()); never executed: QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(data.data()); | 0 | ||||||||||||||||||
| 1580 | - | |||||||||||||||||||
| 1581 | if (data->ref.load() != 1) {
| 0 | ||||||||||||||||||
| 1582 | *this = copy(); | - | ||||||||||||||||||
| 1583 | } never executed: end of block | 0 | ||||||||||||||||||
| 1584 | ++data->detach_no; | - | ||||||||||||||||||
| 1585 | } never executed: end of block | 0 | ||||||||||||||||||
| 1586 | - | |||||||||||||||||||
| 1587 | /*! | - | ||||||||||||||||||
| 1588 | \fn QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 1589 | - | |||||||||||||||||||
| 1590 | Converts the given \a image to a pixmap using the specified \a | - | ||||||||||||||||||
| 1591 | flags to control the conversion. The \a flags argument is a | - | ||||||||||||||||||
| 1592 | bitwise-OR of the \l{Qt::ImageConversionFlags}. Passing 0 for \a | - | ||||||||||||||||||
| 1593 | flags sets all the default options. | - | ||||||||||||||||||
| 1594 | - | |||||||||||||||||||
| 1595 | In case of monochrome and 8-bit images, the image is first | - | ||||||||||||||||||
| 1596 | converted to a 32-bit pixmap and then filled with the colors in | - | ||||||||||||||||||
| 1597 | the color table. If this is too expensive an operation, you can | - | ||||||||||||||||||
| 1598 | use QBitmap::fromImage() instead. | - | ||||||||||||||||||
| 1599 | - | |||||||||||||||||||
| 1600 | \sa fromImageReader(), toImage(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} | - | ||||||||||||||||||
| 1601 | */ | - | ||||||||||||||||||
| 1602 | QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 1603 | { | - | ||||||||||||||||||
| 1604 | if (image.isNull())
| 0 | ||||||||||||||||||
| 1605 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||||||||
| 1606 | - | |||||||||||||||||||
| 1607 | QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); | - | ||||||||||||||||||
| 1608 | data->fromImage(image, flags); | - | ||||||||||||||||||
| 1609 | return QPixmap(data.take()); never executed: return QPixmap(data.take()); | 0 | ||||||||||||||||||
| 1610 | } | - | ||||||||||||||||||
| 1611 | - | |||||||||||||||||||
| 1612 | /*! | - | ||||||||||||||||||
| 1613 | \fn QPixmap QPixmap::fromImage(QImage &&image, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 1614 | \since 5.3 | - | ||||||||||||||||||
| 1615 | \overload | - | ||||||||||||||||||
| 1616 | - | |||||||||||||||||||
| 1617 | Converts the given \a image to a pixmap without copying if possible. | - | ||||||||||||||||||
| 1618 | */ | - | ||||||||||||||||||
| 1619 | - | |||||||||||||||||||
| 1620 | - | |||||||||||||||||||
| 1621 | /*! | - | ||||||||||||||||||
| 1622 | \internal | - | ||||||||||||||||||
| 1623 | */ | - | ||||||||||||||||||
| 1624 | QPixmap QPixmap::fromImageInPlace(QImage &image, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 1625 | { | - | ||||||||||||||||||
| 1626 | if (image.isNull())
| 0 | ||||||||||||||||||
| 1627 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||||||||
| 1628 | - | |||||||||||||||||||
| 1629 | QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); | - | ||||||||||||||||||
| 1630 | data->fromImageInPlace(image, flags); | - | ||||||||||||||||||
| 1631 | return QPixmap(data.take()); never executed: return QPixmap(data.take()); | 0 | ||||||||||||||||||
| 1632 | } | - | ||||||||||||||||||
| 1633 | - | |||||||||||||||||||
| 1634 | /*! | - | ||||||||||||||||||
| 1635 | \fn QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 1636 | - | |||||||||||||||||||
| 1637 | Create a QPixmap from an image read directly from an \a imageReader. | - | ||||||||||||||||||
| 1638 | The \a flags argument is a bitwise-OR of the \l{Qt::ImageConversionFlags}. | - | ||||||||||||||||||
| 1639 | Passing 0 for \a flags sets all the default options. | - | ||||||||||||||||||
| 1640 | - | |||||||||||||||||||
| 1641 | On some systems, reading an image directly to QPixmap can use less memory than | - | ||||||||||||||||||
| 1642 | reading a QImage to convert it to QPixmap. | - | ||||||||||||||||||
| 1643 | - | |||||||||||||||||||
| 1644 | \sa fromImage(), toImage(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} | - | ||||||||||||||||||
| 1645 | */ | - | ||||||||||||||||||
| 1646 | QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||
| 1647 | { | - | ||||||||||||||||||
| 1648 | QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); | - | ||||||||||||||||||
| 1649 | data->fromImageReader(imageReader, flags); | - | ||||||||||||||||||
| 1650 | return QPixmap(data.take()); never executed: return QPixmap(data.take()); | 0 | ||||||||||||||||||
| 1651 | } | - | ||||||||||||||||||
| 1652 | - | |||||||||||||||||||
| 1653 | /*! | - | ||||||||||||||||||
| 1654 | \fn QPixmap QPixmap::grabWindow(WId window, int x, int y, int | - | ||||||||||||||||||
| 1655 | width, int height) | - | ||||||||||||||||||
| 1656 | - | |||||||||||||||||||
| 1657 | Creates and returns a pixmap constructed by grabbing the contents | - | ||||||||||||||||||
| 1658 | of the given \a window restricted by QRect(\a x, \a y, \a width, | - | ||||||||||||||||||
| 1659 | \a height). | - | ||||||||||||||||||
| 1660 | - | |||||||||||||||||||
| 1661 | The arguments (\a{x}, \a{y}) specify the offset in the window, | - | ||||||||||||||||||
| 1662 | whereas (\a{width}, \a{height}) specify the area to be copied. If | - | ||||||||||||||||||
| 1663 | \a width is negative, the function copies everything to the right | - | ||||||||||||||||||
| 1664 | border of the window. If \a height is negative, the function | - | ||||||||||||||||||
| 1665 | copies everything to the bottom of the window. | - | ||||||||||||||||||
| 1666 | - | |||||||||||||||||||
| 1667 | The window system identifier (\c WId) can be retrieved using the | - | ||||||||||||||||||
| 1668 | QWidget::winId() function. The rationale for using a window | - | ||||||||||||||||||
| 1669 | identifier and not a QWidget, is to enable grabbing of windows | - | ||||||||||||||||||
| 1670 | that are not part of the application, window system frames, and so | - | ||||||||||||||||||
| 1671 | on. | - | ||||||||||||||||||
| 1672 | - | |||||||||||||||||||
| 1673 | The grabWindow() function grabs pixels from the screen, not from | - | ||||||||||||||||||
| 1674 | the window, i.e. if there is another window partially or entirely | - | ||||||||||||||||||
| 1675 | over the one you grab, you get pixels from the overlying window, | - | ||||||||||||||||||
| 1676 | too. The mouse cursor is generally not grabbed. | - | ||||||||||||||||||
| 1677 | - | |||||||||||||||||||
| 1678 | Note on X11 that if the given \a window doesn't have the same depth | - | ||||||||||||||||||
| 1679 | as the root window, and another window partially or entirely | - | ||||||||||||||||||
| 1680 | obscures the one you grab, you will \e not get pixels from the | - | ||||||||||||||||||
| 1681 | overlying window. The contents of the obscured areas in the | - | ||||||||||||||||||
| 1682 | pixmap will be undefined and uninitialized. | - | ||||||||||||||||||
| 1683 | - | |||||||||||||||||||
| 1684 | On Windows Vista and above grabbing a layered window, which is | - | ||||||||||||||||||
| 1685 | created by setting the Qt::WA_TranslucentBackground attribute, will | - | ||||||||||||||||||
| 1686 | not work. Instead grabbing the desktop widget should work. | - | ||||||||||||||||||
| 1687 | - | |||||||||||||||||||
| 1688 | \warning In general, grabbing an area outside the screen is not | - | ||||||||||||||||||
| 1689 | safe. This depends on the underlying window system. | - | ||||||||||||||||||
| 1690 | - | |||||||||||||||||||
| 1691 | \warning The function is deprecated in Qt 5.0 since there might be | - | ||||||||||||||||||
| 1692 | platform plugins in which window system identifiers (\c WId) | - | ||||||||||||||||||
| 1693 | are local to a screen. Use QScreen::grabWindow() instead. | - | ||||||||||||||||||
| 1694 | - | |||||||||||||||||||
| 1695 | \sa grabWidget(), {Screenshot Example} | - | ||||||||||||||||||
| 1696 | \sa QScreen | - | ||||||||||||||||||
| 1697 | \deprecated | - | ||||||||||||||||||
| 1698 | */ | - | ||||||||||||||||||
| 1699 | - | |||||||||||||||||||
| 1700 | QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h) | - | ||||||||||||||||||
| 1701 | { | - | ||||||||||||||||||
| 1702 | qWarning("this function is deprecated, use QScreen::grabWindow() instead." | - | ||||||||||||||||||
| 1703 | " Defaulting to primary screen."); | - | ||||||||||||||||||
| 1704 | return QGuiApplication::primaryScreen()->grabWindow(window, x, y, w, h); never executed: return QGuiApplication::primaryScreen()->grabWindow(window, x, y, w, h); | 0 | ||||||||||||||||||
| 1705 | } | - | ||||||||||||||||||
| 1706 | - | |||||||||||||||||||
| 1707 | /*! | - | ||||||||||||||||||
| 1708 | \internal | - | ||||||||||||||||||
| 1709 | */ | - | ||||||||||||||||||
| 1710 | QPlatformPixmap* QPixmap::handle() const | - | ||||||||||||||||||
| 1711 | { | - | ||||||||||||||||||
| 1712 | return data.data(); never executed: return data.data(); | 0 | ||||||||||||||||||
| 1713 | } | - | ||||||||||||||||||
| 1714 | - | |||||||||||||||||||
| 1715 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||
| 1716 | QDebug operator<<(QDebug dbg, const QPixmap &r) | - | ||||||||||||||||||
| 1717 | { | - | ||||||||||||||||||
| 1718 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
| 1719 | dbg.resetFormat(); | - | ||||||||||||||||||
| 1720 | dbg.nospace(); | - | ||||||||||||||||||
| 1721 | dbg << "QPixmap("; | - | ||||||||||||||||||
| 1722 | if (r.isNull()) {
| 0 | ||||||||||||||||||
| 1723 | dbg << "null"; | - | ||||||||||||||||||
| 1724 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1725 | dbg << r.size() << ",depth=" << r.depth() | - | ||||||||||||||||||
| 1726 | << ",devicePixelRatio=" << r.devicePixelRatio() | - | ||||||||||||||||||
| 1727 | << ",cacheKey=" << showbase << hex << r.cacheKey() << dec << noshowbase; | - | ||||||||||||||||||
| 1728 | } never executed: end of block | 0 | ||||||||||||||||||
| 1729 | dbg << ')'; | - | ||||||||||||||||||
| 1730 | return dbg; never executed: return dbg; | 0 | ||||||||||||||||||
| 1731 | } | - | ||||||||||||||||||
| 1732 | #endif | - | ||||||||||||||||||
| 1733 | - | |||||||||||||||||||
| 1734 | /*! | - | ||||||||||||||||||
| 1735 | \fn QPixmap QPixmap::alphaChannel() const | - | ||||||||||||||||||
| 1736 | - | |||||||||||||||||||
| 1737 | Most use cases for this can be achieved using a QPainter and QPainter::CompositionMode instead. | - | ||||||||||||||||||
| 1738 | */ | - | ||||||||||||||||||
| 1739 | - | |||||||||||||||||||
| 1740 | /*! | - | ||||||||||||||||||
| 1741 | \fn void QPixmap::setAlphaChannel(const QPixmap &p) | - | ||||||||||||||||||
| 1742 | - | |||||||||||||||||||
| 1743 | Most use cases for this can be achieved using \a p with QPainter and QPainter::CompositionMode instead. | - | ||||||||||||||||||
| 1744 | */ | - | ||||||||||||||||||
| 1745 | - | |||||||||||||||||||
| 1746 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |