download qbitmap.cpp
Language: C++
License: GPL
Copyright: (C) 1992-2002 Trolltech AS. All rights reserved.
LOC: 87
Project Info
FacturaLUX
Server: SourceForge
Type: cvs
...rototipo\src\qt\src\kernel\
   makepsheader.pl
   q1xcompatibility.h
   qabstractlayout.cpp
   qabstractlayout.h
   qaccel.cpp
   qaccel.h
   qaccessible.cpp
   qaccessible.h
   qapplication.cpp
   qapplication.h
   qapplication_p.h
   qapplication_x11.cpp
   qasyncimageio.cpp
   qasyncimageio.h
   qasyncio.cpp
   qasyncio.h
   qbitmap.cpp
   qbitmap.h
   qbrush.h
   qclipboard.cpp
   qclipboard.h
   qclipboard_x11.cpp
   qcolor.cpp
   qcolor.h
   qcolor_p.cpp
   qcolor_p.h
   qcolor_x11.cpp
   qcomplextext.cpp
   qcomplextext_p.h
   qconnection.cpp
   qconnection.h
   qcursor.cpp
   qcursor.h
   qcursor_x11.cpp
   qdesktopwidget.h
   qdesktopwidget_x11.cpp
   qdnd_x11.cpp
   qdragobject.cpp
   qdragobject.h
   qdrawutil.cpp
   qdrawutil.h
   qdropsite.cpp
   qdropsite.h
   qevent.cpp
   qevent.h
   qeventloop.cpp
   qeventloop.h
   qeventloop_p.h
   qeventloop_unix.cpp
   qeventloop_x11.cpp
   qfocusdata.cpp
   qfocusdata.h
   qfont.cpp
   qfont.h
   qfont_x11.cpp
   qfontdata_p.h
   qfontdatabase.cpp
   qfontdatabase.h
   qfontdatabase_x11.cpp
   qfontengine_p.h
   qfontengine_x11.cpp
   qfontinfo.h
   qfontmetrics.h
   qgif.h
   qgplugin.cpp
   qgplugin.h
   qguardedptr.cpp
   qguardedptr.h
   qiconset.cpp
   qiconset.h
   qimage.cpp
   qimage.h
   qimageformatinterface_p.h
   qimageformatplugin.cpp
   qimageformatplugin.h
   qinputcontext_p.h
   qinputcontext_x11.cpp
   qinternal.cpp
   qinternal_p.h
   qjpegio.cpp
   qjpegio.h
   qkeycode.h
   qkeysequence.cpp
   qkeysequence.h
   qlayout.cpp
   qlayout.h
   qlayoutengine.cpp
   qlayoutengine_p.h
   qlocalfs.cpp
   qlocalfs.h
   qlock.cpp
   qlock_p.h
   qmetaobject.cpp
   qmetaobject.h
   qmime.cpp
   qmime.h
   qmngio.cpp
   qmngio.h
   qmotifdnd_x11.cpp
   qmovie.cpp
   qmovie.h
   qnamespace.h
   qnetworkprotocol.cpp
   qnetworkprotocol.h
   qobject.cpp
   qobject.h
   qobjectcleanuphandler.cpp
   qobjectcleanuphandler.h
   qobjectdefs.h
   qobjectdict.h
   qobjectlist.h
   qpaintdevice.h
   qpaintdevice_x11.cpp
   qpaintdevicedefs.h
   qpaintdevicemetrics.cpp
   qpaintdevicemetrics.h
   qpainter.cpp
   qpainter.h
   qpainter_p.h
   qpainter_x11.cpp
   qpalette.cpp
   qpalette.h
   qpen.h
   qpicture.cpp
   qpicture.h
   qpixmap.cpp
   qpixmap.h
   qpixmap_x11.cpp
   qpixmapcache.cpp
   qpixmapcache.h
   qpngio.cpp
   qpngio.h
   qpoint.cpp
   qpoint.h
   qpointarray.cpp
   qpointarray.h
   qpolygonscanner.cpp
   qpolygonscanner.h
   qprinter.cpp
   qprinter.h
   qprinter_p.h
   qprinter_unix.cpp
   qprocess.cpp
   qprocess.h
   qprocess_unix.cpp
   qpsprinter.cpp
   qpsprinter.ps
   qpsprinter_p.h
   qrect.cpp
   qrect.h
   qregion.cpp
   qregion.h
   qregion_x11.cpp
   qrichtext.cpp
   qrichtext_p.cpp
   qrichtext_p.h
   qscriptengine.cpp
   qscriptengine_p.h
   qscriptengine_x11.cpp
   qsession.h
   qsessionmanager.h
   qsharedmemory_p.cpp
   qsharedmemory_p.h
   qsignal.cpp
   qsignal.h
   qsignalmapper.cpp
   qsignalmapper.h
   qsignalslotimp.h
   qsimplerichtext.cpp
   qsimplerichtext.h
   qsize.cpp
   qsize.h
   qsizegrip.cpp
   qsizegrip.h
   qsizepolicy.h
   qsocketnotifier.cpp
   qsocketnotifier.h
   qsound.cpp
   qsound.h
   qsound_x11.cpp
   qstyle.cpp
   qstyle.h
   qstylesheet.cpp
   qstylesheet.h
   qt.h
   qt_compat.pri
   qt_gfx.pri
   qt_kernel.pri
   qt_x11.pri
   qt_x11_p.h
   qtaddons_x11.cpp
   qtextengine.cpp
   qtextengine_p.h
   qtextengine_unix.cpp
   qtextlayout.cpp
   qtextlayout_p.h
   qthread.cpp
   qthread.h
   qthread_unix.cpp
   qtimer.cpp
   qtimer.h
   qtranslator.cpp
   qtranslator.h
   qucomextra.cpp
   qucomextra_p.h
   qurl.cpp
   qurl.h
   qurlinfo.cpp
   qurlinfo.h
   qurloperator.cpp
   qurloperator.h
   qvariant.cpp
   qvariant.h
   qvfbhdr.h
   qwidget.cpp
   qwidget.h
   qwidget_p.h
   qwidget_x11.cpp
   qwidgetcreate_x11.cpp
   qwidgetintdict.h
   qwidgetlist.h
   qwindow.cpp
   qwindow.h
   qwindowdefs.h
   qwmatrix.cpp
   qwmatrix.h

/****************************************************************************
** $Id: qbitmap.cpp,v 1.1 2003/12/04 08:17:52 falbujer Exp $
**
** Implementation of QBitmap class
**
** Created : 941020
**
** Copyright (C) 1992-2002 Trolltech AS.  All rights reserved.
**
** This file is part of the kernel module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
**   information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/

#include "qbitmap.h"
#include "qimage.h"


/*!
    \class QBitmap qbitmap.h
    \brief The QBitmap class provides monochrome (1-bit depth) pixmaps.

    \ingroup graphics
    \ingroup images
    \ingroup shared

    The QBitmap class is a monochrome off-screen paint device used
    mainly for creating custom QCursor and QBrush objects, in
    QPixmap::setMask() and for QRegion.

    A QBitmap is a QPixmap with a \link QPixmap::depth() depth\endlink
    of 1. If a pixmap with a depth greater than 1 is assigned to a
    bitmap, the bitmap will be dithered automatically. A QBitmap is
    guaranteed to always have the depth 1, unless it is
    QPixmap::isNull() which has depth 0.

    When drawing in a QBitmap (or QPixmap with depth 1), we recommend
    using the  QColor objects \c Qt::color0 and \c Qt::color1.
    Painting with \c color0 sets the bitmap bits to 0, and painting
    with \c color1 sets the bits to 1. For a bitmap, 0-bits indicate
    background (or transparent) and 1-bits indicate foreground (or
    opaque). Using the \c black and \c white QColor objects make no
    sense because the QColor::pixel() value is not necessarily 0 for
    black and 1 for white.

    The QBitmap can be transformed (translated, scaled, sheared or
    rotated) using xForm().

    Just like the QPixmap class, QBitmap is optimized by the use of
    \link shclass.html implicit sharing\endlink, so it is very
    efficient to pass QBitmap objects as arguments.

    \sa QPixmap, QPainter::drawPixmap(), bitBlt(), \link shclass.html Shared Classes\endlink
*/


/*!
    Constructs a null bitmap.

    \sa QPixmap::isNull()
*/

QBitmap::QBitmap()
{
    data->bitmap = TRUE;
}


/*!
    Constructs a bitmap with width \a w and height \a h.

    The contents of the bitmap is uninitialized if \a clear is FALSE;
    otherwise it is filled with pixel value 0 (the QColor \c
    Qt::color0).

    The optional \a optimization argument specifies the optimization
    setting for the bitmap. The default optimization should be used in
    most cases. Games and other pixmap-intensive applications may
    benefit from setting this argument; see \l{QPixmap::Optimization}.

    \sa QPixmap::setOptimization(), QPixmap::setDefaultOptimization()
*/

QBitmap::QBitmap( int w, int h, bool clear,
		  QPixmap::Optimization optimization )
    : QPixmap( w, h, 1, optimization )
{
    data->bitmap = TRUE;
    if ( clear )
	fill( Qt::color0 );
}


/*!
    \overload

    Constructs a bitmap with the size \a size.

    The contents of the bitmap is uninitialized if \a clear is FALSE;
    otherwise it is filled with pixel value 0 (the QColor \c
    Qt::color0).

    The optional \a optimization argument specifies the optimization
    setting for the bitmap. The default optimization should be used in
    most cases. Games and other pixmap-intensive applications may
    benefit from setting this argument; see \l{QPixmap::Optimization}.
*/

QBitmap::QBitmap( const QSize &size, bool clear,
		  QPixmap::Optimization optimization )
    : QPixmap( size, 1, optimization )
{
    data->bitmap = TRUE;
    if ( clear )
	fill( Qt::color0 );
}


/*!
    Constructs a bitmap with width \a w and height \a h and sets the
    contents to \a bits.

    The \a isXbitmap flag should be TRUE if \a bits was generated by
    the X11 bitmap program. The X bitmap bit order is little endian.
    The QImage documentation discusses bit order of monochrome images.

    Example (creates an arrow bitmap):
    \code
	uchar arrow_bits[] = { 0x3f, 0x1f, 0x0f, 0x1f, 0x3b, 0x71, 0xe0, 0xc0 };
	QBitmap bm( 8, 8, arrow_bits, TRUE );
    \endcode
*/

QBitmap::QBitmap( int w, int h, const uchar *bits, bool isXbitmap )
    : QPixmap( w, h, bits, isXbitmap )
{
    data->bitmap = TRUE;
}


/*!
    \overload

    Constructs a bitmap with the size \a size and sets the contents to
    \a bits.

    The \a isXbitmap flag should be TRUE if \a bits was generated by
    the X11 bitmap program. The X bitmap bit order is little endian.
    The QImage documentation discusses bit order of monochrome images.
*/

QBitmap::QBitmap( const QSize &size, const uchar *bits, bool isXbitmap )
    : QPixmap( size.width(), size.height(), bits, isXbitmap )
{
    data->bitmap = TRUE;
}


/*!
    Constructs a bitmap that is a copy of \a bitmap.
*/

QBitmap::QBitmap( const QBitmap &bitmap )
    : QPixmap( bitmap )
{
}

#ifndef QT_NO_IMAGEIO
/*!
    Constructs a bitmap from the file \a fileName. If the file does
    not exist or is of an unknown format, the bitmap becomes a null
    bitmap.

    The parameters \a fileName and \a format are passed on to
    QPixmap::load(). Dithering will be performed if the file format
    uses more than 1 bit per pixel.

    \sa QPixmap::isNull(), QPixmap::load(), QPixmap::loadFromData(),
    QPixmap::save(), QPixmap::imageFormat()
*/

QBitmap::QBitmap( const QString& fileName, const char *format )
    : QPixmap() // Will set bitmap to null bitmap, explicit call for clarity
{
    data->bitmap = TRUE;
    load( fileName, format, Mono );
}
#endif

/*!
    Assigns the bitmap \a bitmap to this bitmap and returns a
    reference to this bitmap.
*/

QBitmap &QBitmap::operator=( const QBitmap &bitmap )
{
    QPixmap::operator=(bitmap);
#if defined(QT_CHECK_STATE)
    Q_ASSERT( data->bitmap );
#endif
    return *this;
}


/*!
    \overload

    Assigns the pixmap \a pixmap to this bitmap and returns a
    reference to this bitmap.

    Dithering will be performed if the pixmap has a QPixmap::depth()
    greater than 1.
*/

QBitmap &QBitmap::operator=( const QPixmap &pixmap )
{
    if ( pixmap.isNull() ) {			// a null pixmap
	QBitmap bm( 0, 0, FALSE, pixmap.optimization() );
	QBitmap::operator=(bm);
    } else if ( pixmap.depth() == 1 ) {		// 1-bit pixmap
	if ( pixmap.isQBitmap() ) {		// another QBitmap
	    QPixmap::operator=(pixmap);		// shallow assignment
	} else {				// not a QBitmap, but 1-bit
	    QBitmap bm( pixmap.size(), FALSE, pixmap.optimization() );
	    bitBlt( &bm, 0,0, &pixmap, 0,0,pixmap.width(),pixmap.height() );
	    QBitmap::operator=(bm);
	}
    } else {					// n-bit depth pixmap
	QImage image;
	image = pixmap;				// convert pixmap to image
	*this = image;				// will dither image
    }
    return *this;
}


/*!
    \overload

    Converts the image \a image to a bitmap and assigns the result to
    this bitmap. Returns a reference to the bitmap.

    Dithering will be performed if the image has a QImage::depth()
    greater than 1.
*/

QBitmap &QBitmap::operator=( const QImage &image )
{
    convertFromImage( image );
    return *this;
}


#ifndef QT_NO_PIXMAP_TRANSFORMATION
/*!
    Returns a transformed copy of this bitmap by using \a matrix.

    This function does exactly the same as QPixmap::xForm(), except
    that it returns a QBitmap instead of a QPixmap.

    \sa QPixmap::xForm()
*/

QBitmap QBitmap::xForm( const QWMatrix &matrix ) const
{
    QPixmap pm = QPixmap::xForm( matrix );
    QBitmap bm;
    // Here we fake the pixmap to think it's a QBitmap. With this trick,
    // the QBitmap::operator=(const QPixmap&) will just refer the
    // pm.data and we do not need to perform a bitBlt.
    pm.data->bitmap = TRUE;
    bm = pm;
    return bm;
}
#endif // QT_NO_TRANSFORMATIONS



About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us