Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/qpixmap_raster.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5151#include <private/qdrawhelper_p.h>
    5252
    53 #if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
    54 #include <private/qpaintengine_d3d_p.h>
    55 #include <d3d9.h>
    56 extern QDirect3DPaintEngine *qt_d3dEngine();
    57 #endif
    58 
    5953QT_BEGIN_NAMESPACE
    6054
     
    6256                                     0x10, 0x20, 0x40, 0x80 };
    6357
     58QPixmap qt_toRasterPixmap(const QImage &image)
     59{
     60    QPixmapData *data =
     61        new QRasterPixmapData(image.depth() == 1
     62                           ? QPixmapData::BitmapType
     63                           : QPixmapData::PixmapType);
     64
     65    data->fromImage(image, Qt::AutoColor);
     66
     67    return QPixmap(data);
     68}
     69
     70QPixmap qt_toRasterPixmap(const QPixmap &pixmap)
     71{
     72    if (pixmap.isNull())
     73        return QPixmap();
     74
     75    if (QPixmap(pixmap).data_ptr()->classId() == QPixmapData::RasterClass)
     76        return pixmap;
     77
     78    return qt_toRasterPixmap(pixmap.toImage());
     79}
     80
    6481QRasterPixmapData::QRasterPixmapData(PixelType type)
    6582    : QPixmapData(type, RasterClass)
    66 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
    67     , texture(0)
    68 #endif
    6983{
    7084}
     
    7286QRasterPixmapData::~QRasterPixmapData()
    7387{
     88}
     89
     90QPixmapData *QRasterPixmapData::createCompatiblePixmapData() const
     91{
     92    return new QRasterPixmapData(pixelType());
    7493}
    7594
     
    95114
    96115    image = QImage(width, height, format);
     116    w = width;
     117    h = height;
     118    d = image.depth();
     119    is_null = (w <= 0 || h <= 0);
    97120
    98121    if (pixelType() == BitmapType && !image.isNull()) {
    99         image.setNumColors(2);
     122        image.setColorCount(2);
    100123        image.setColor(0, QColor(Qt::color0).rgba());
    101124        image.setColor(1, QColor(Qt::color1).rgba());
     
    178201    }
    179202#endif
     203    if (image.d) {
     204        w = image.d->width;
     205        h = image.d->height;
     206        d = image.d->depth;
     207    } else {
     208        w = h = d = 0;
     209    }
     210    is_null = (w <= 0 || h <= 0);
    180211
    181212    setSerialNumber(image.serialNumber());
     213}
     214
     215// from qwindowsurface.cpp
     216extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
     217
     218bool QRasterPixmapData::scroll(int dx, int dy, const QRect &rect)
     219{
     220    if (!image.isNull())
     221        qt_scrollRectInImage(image, rect, QPoint(dx, dy));
     222    return true;
    182223}
    183224
     
    322363int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
    323364{
     365    QImageData *d = image.d;
     366    if (!d)
     367        return 0;
     368
    324369    // override the image dpi with the screen dpi when rendering to a pixmap
    325     const int dpmX = qRound(qt_defaultDpiX() * 100 / qreal(2.54));
    326     const int dpmY = qRound(qt_defaultDpiY() * 100 / qreal(2.54));
    327370    switch (metric) {
     371    case QPaintDevice::PdmWidth:
     372        return w;
     373    case QPaintDevice::PdmHeight:
     374        return h;
    328375    case QPaintDevice::PdmWidthMM:
    329         return qRound(image.width() * 1000 / dpmX);
     376        return qRound(d->width * 25.4 / qt_defaultDpiX());
    330377    case QPaintDevice::PdmHeightMM:
    331         return qRound(image.height() * 1000 / dpmY);
    332     case QPaintDevice::PdmDpiX:
    333         return qRound(dpmX * qreal(0.0254));
    334     case QPaintDevice::PdmDpiY:
    335         return qRound(dpmY * qreal(0.0254));
     378        return qRound(d->height * 25.4 / qt_defaultDpiY());
     379    case QPaintDevice::PdmNumColors:
     380        return d->colortable.size();
     381    case QPaintDevice::PdmDepth:
     382        return this->d;
     383    case QPaintDevice::PdmDpiX: // fall-through
    336384    case QPaintDevice::PdmPhysicalDpiX:
    337         return qRound(dpmX * qreal(0.0254));
     385        return qt_defaultDpiX();
     386    case QPaintDevice::PdmDpiY: // fall-through
    338387    case QPaintDevice::PdmPhysicalDpiY:
    339         return qRound(dpmY * qreal(0.0254));
     388        return qt_defaultDpiY();
    340389    default:
    341         return image.metric(metric);
    342     }
     390        qWarning("QRasterPixmapData::metric(): Unhandled metric type %d", metric);
     391        break;
     392    }
     393
     394    return 0;
    343395}
    344396
Note: See TracChangeset for help on using the changeset viewer.