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

📄 qpixmap.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 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://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** 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/qinternal_p.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"#if defined(Q_WS_X11)#include "qx11info_x11.h"#include <private/qt_x11_p.h>#endiftypedef void (*_qt_pixmap_cleanup_hook)(int);Q_GUI_EXPORT _qt_pixmap_cleanup_hook qt_pixmap_cleanup_hook = 0;Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap){    return -(((qint64) pixmap.data->ser_no) << 32) | ((qint64) (pixmap.data->detach_no));}/*!    \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);    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 QMatrix &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}*/QMatrix QPixmap::trueMatrix(const QMatrix &m, int w, int h){    return QImage::trueMatrix(m, w, h);}/*!    \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;    }    int d = data->d;    // Create new pixmap    QPixmap pm(QSize(w, h), d == 1 ? BitmapType : PixmapType);#ifdef Q_WS_X11    pm.x11SetScreen(data->xinfo.screen());#endif // Q_WS_X11    if (!data->uninit && !isNull()) {                // has existing pixmap        // Copy old pixmap        QPainter p(&pm);        p.drawPixmap(0, 0, *this, 0, 0, qMin(width(), w), qMin(height(), h));    }#if defined(Q_WS_MAC)    if(data->qd_alpha) {        data->macQDUpdateAlpha();    } else#endif // Q_WS_X11#ifdef Q_WS_X11        if (data->x11_mask) {            pm.data->x11_mask = (Qt::HANDLE)XCreatePixmap(X11->display, RootWindow(data->xinfo.display(), data->xinfo.screen()),

⌨️ 快捷键说明

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