⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpixmap.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <qglobal.h>#include "qpixmap.h"#include "qpixmap_p.h"#include "qbitmap.h"#include "qimage.h"#include "qwidget.h"#include "qpainter.h"#include "qdatastream.h"#include "qbuffer.h"#include "qapplication.h"#include <private/qwidget_p.h>#include "qevent.h"#include "qfile.h"#include "qfileinfo.h"#include "qpixmapcache.h"#include "qdatetime.h"#include "qimagereader.h"#include "qimagewriter.h"#include "qpaintengine.h"#ifdef Q_WS_MAC# include "private/qt_mac_p.h"#endif#if defined(Q_WS_X11)# include "qx11info_x11.h"# include <private/qt_x11_p.h>#endif// ### Qt 5: removetypedef void (*_qt_pixmap_cleanup_hook)(int);Q_GUI_EXPORT _qt_pixmap_cleanup_hook qt_pixmap_cleanup_hook = 0;// ### Qt 5: renametypedef void (*_qt_pixmap_cleanup_hook_64)(qint64);Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64 = 0;// ### Qt 5: removeQ_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap){    return pixmap.cacheKey();}/*!    \enum QPixmap::ColorMode    \compat    This enum type defines the color modes that exist for converting    QImage objects to QPixmap.  It is provided here for compatibility    with earlier versions of Qt.    Use Qt::ImageConversionFlags instead.    \value Auto  Select \c Color or \c Mono on a case-by-case basis.    \value Color Always create colored pixmaps.    \value Mono  Always create bitmaps.*//*!    Constructs a null pixmap.    \sa isNull()*/QPixmap::QPixmap()    : QPaintDevice(){    init(0, 0);}/*!    \fn QPixmap::QPixmap(int width, int height)    Constructs a pixmap with the given \a width and \a height.    The content of the pixmap is uninitialized.  If either \a width or    \a height is zero, a null pixmap is constructed.    \sa isNull()*/QPixmap::QPixmap(int w, int h)    : QPaintDevice(){    init(w, h);}/*!    \overload    Constructs a pixmap of the given \a size.*/QPixmap::QPixmap(const QSize &size)    : QPaintDevice(){    init(size.width(), size.height());}/*!  \internal*/QPixmap::QPixmap(const QSize &s, Type type){    init(s.width(), s.height(), type);}/*!    Constructs a pixmap from the file with the given \a fileName. If the    file does not exist or is of an unknown format, the pixmap becomes a    null pixmap.    The loader attempts to read the pixmap using the specified \a    format. If the \a format is not specified (which is the default),    the loader probes the file for a header to guess the file format.    The file name can either refer to an actual file on disk or to    one of the application's embedded resources. See the    \l{resources.html}{Resource System} overview for details on how    to embed images and other resource files in the application's    executable.    If the image needs to be modified to fit in a lower-resolution    result (e.g. converting from 32-bit to 8-bit), use the \a    flags to control the conversion.    The \a fileName, \a format and \a flags parameters are    passed on to load(). This means that the data in \a fileName is    not compiled into the binary. If \a fileName contains a relative    path (e.g. the filename only) the relevant file must be found    relative to the runtime working directory.    \sa {QPixmap#Reading and Writing Image Files}{Reading and Writing    Image Files}*/QPixmap::QPixmap(const QString& fileName, const char *format, Qt::ImageConversionFlags flags)    : QPaintDevice(){    init(0, 0);    load(fileName, format, flags);}/*!    Constructs a pixmap that is a copy of the given \a pixmap.    \sa copy()*/QPixmap::QPixmap(const QPixmap &pixmap)    : QPaintDevice(){    if (pixmap.paintingActive()) {                // make a deep copy        data = 0;        operator=(pixmap.copy());    } else {        data = pixmap.data;        data->ref();    }}/*!    Constructs a pixmap from the given \a xpm data, which must be a    valid XPM image.    Errors are silently ignored.    Note that it's possible to squeeze the XPM variable a little bit    by using an unusual declaration:    \code        static const char * const start_xpm[]={            "16 15 8 1",            "a c #cec6bd",        ....    \endcode    The extra \c const makes the entire definition read-only, which is    slightly more efficient (for example, when the code is in a shared    library) and ROMable when the application is to be stored in ROM.*/QPixmap::QPixmap(const char * const xpm[])    : QPaintDevice(){    init(0, 0);    if (!xpm)        return;    QImage image(xpm);    if (!image.isNull()) {        if (data->type == BitmapType)            *this =  QBitmap::fromImage(image);        else            *this = fromImage(image);    }}/*!    Destroys the pixmap.*/QPixmap::~QPixmap(){    deref();}/*!  \internal*/int QPixmap::devType() const{    return QInternal::Pixmap;}/*!    \fn QPixmap QPixmap::copy(int x, int y, int width, int height) const    \overload    Returns a deep copy of the subset of the pixmap that is specified    by the rectangle QRect( \a x, \a y, \a width, \a height).*//*!    \fn QPixmap QPixmap::copy(const QRect &rectangle) const    Returns a deep copy of the subset of the pixmap that is specified    by the given \a rectangle. For more information on deep copies,    see the \l {Implicit Data Sharing} documentation.    If the given \a rectangle is empty, the whole image is copied.    \sa operator=(), QPixmap(), {QPixmap#Pixmap    Transformations}{Pixmap Transformations}*/#if defined(Q_WS_WIN) || defined(Q_WS_QWS)QPixmap QPixmap::copy(const QRect &rect) const{    QPixmap pm;    if (data->type == BitmapType)        pm = QBitmap::fromImage(toImage().copy(rect));    else        pm = fromImage(toImage().copy(rect));    return pm;}#endif/*!    Assigns the given \a pixmap to this pixmap and returns a reference    to this pixmap.    \sa copy(), QPixmap()*/QPixmap &QPixmap::operator=(const QPixmap &pixmap){    if (paintingActive()) {        qWarning("QPixmap::operator=: Cannot assign to pixmap during painting");        return *this;    }    if (pixmap.paintingActive()) {                // make a deep copy        *this = pixmap.copy();    } else {        pixmap.data->ref();                                // avoid 'x = x'        deref();        data = pixmap.data;    }    return *this;}/*!   Returns the pixmap as a QVariant.*/QPixmap::operator QVariant() const{    return QVariant(QVariant::Pixmap, this);}/*!    \fn bool QPixmap::operator!() const    Returns true if this is a null pixmap; otherwise returns false.    \sa isNull()*//*!    \fn QPixmap::operator QImage() const    Returns the pixmap as a QImage.    Use the toImage() function instead.*//*!    \fn QMatrix QPixmap::trueMatrix(const QTransform &matrix, int width, int height)    Returns the actual matrix used for transforming a pixmap with the    given \a width, \a height and \a matrix.    When transforming a pixmap using the transformed() function, the    transformation matrix is internally adjusted to compensate for    unwanted translation, i.e. transformed() returns the smallest    pixmap containing all transformed points of the original    pixmap. This function returns the modified matrix, which maps    points correctly from the original pixmap into the new pixmap.    \sa transformed(), {QPixmap#Pixmap Transformations}{Pixmap    Transformations}*/QTransform QPixmap::trueMatrix(const QTransform &m, int w, int h){    return QImage::trueMatrix(m, w, h);}/*!  \overload  This convenience function loads the matrix \a m into a  QTransform and calls the overloaded function with the  QTransform and the width \a w and the height \a h. */QMatrix QPixmap::trueMatrix(const QMatrix &m, int w, int h){    return trueMatrix(QTransform(m), w, h).toAffine();}/*!    \fn bool QPixmap::isQBitmap() const    Returns true if this is a QBitmap; otherwise returns false.*//*!    \fn bool QPixmap::isNull() const    Returns true if this is a null pixmap; otherwise returns false.    A null pixmap has zero width, zero height and no contents. You    cannot draw in a null pixmap.*/bool QPixmap::isNull() const{    return data->w == 0;}/*!    \fn int QPixmap::width() const    Returns the width of the pixmap.    \sa size(), {QPixmap#Pixmap Information}{Pixmap Information}*/int QPixmap::width() const{    return data->w;}/*!    \fn int QPixmap::height() const    Returns the height of the pixmap.    \sa size(), {QPixmap#Pixmap Information}{Pixmap Information}*/int QPixmap::height() const{    return data->h;}/*!    \fn QSize QPixmap::size() const    Returns the size of the pixmap.    \sa width(), height(), {QPixmap#Pixmap Information}{Pixmap    Information}*/QSize QPixmap::size() const{    return QSize(data->w,data->h);}/*!    \fn QRect QPixmap::rect() const    Returns the pixmap's enclosing rectangle.    \sa {QPixmap#Pixmap Information}{Pixmap Information}*/QRect QPixmap::rect() const{    return QRect(0,0,data->w,data->h);}/*!    \fn int QPixmap::depth() const    Returns the depth of the pixmap.    The pixmap depth is also called bits per pixel (bpp) or bit planes    of a pixmap. A null pixmap has depth 0.    \sa defaultDepth(), {QPixmap#Pixmap Information}{Pixmap    Information}*/int QPixmap::depth() const{    return data->d;}/*!    \fn void QPixmap::resize(const QSize &size)    \overload    \compat    Use the QPixmap constructor that takes a QSize (\a size) instead.    \oldcode        pixmap.resize(size);    \newcode        pixmap = QPixmap(size);    \endcode*/#ifdef QT3_SUPPORTvoid QPixmap::resize_helper(const QSize &s){    int w = s.width();    int h = s.height();    if (w < 1 || h < 1) {        *this = QPixmap();        return;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -