Source Code (Use browser search to find items of interest.)

Class Index

qt'QImageDrag (./qt-2.1.0/src/kernel/qdragobject.h:107)

class Q_EXPORT QImageDrag: public QDragObject {
    Q_OBJECT
    QImage img;
    QStrList ofmts;
    QImageDragData* d;

public:
    QImageDrag( QImage image,
		QWidget * dragSource = 0, const char * name = 0 );
    QImageDrag( QWidget * dragSource = 0, const char * name = 0 );
    ~QImageDrag();

    virtual void setImage( QImage image );

    const char * format(int i) const;
    virtual QByteArray encodedData(const char*) const;

    static bool canDecode( const QMimeSource* e );
    static bool decode( const QMimeSource* e, QImage& i );
    static bool decode( const QMimeSource* e, QPixmap& i );
};



qt'QImageDrag::QImageDrag() (./qt-2.1.0/src/kernel/qdragobject.cpp:752)

QImageDrag::QImageDrag( QImage image,
			QWidget * dragSource, const char * name )
    : QDragObject( dragSource, name ),
	d(0)
{
    setImage( image );
}

/*!  Constructs a default text drag object.  \a dragSource must be the drag
  source, \a name is the object name.
*/


qt'QImageDrag::QImageDrag() (./qt-2.1.0/src/kernel/qdragobject.cpp:764)

QImageDrag::QImageDrag( QWidget * dragSource, const char * name )
    : QDragObject( dragSource, name ),
	d(0)
{
}


/*!  Destroys the image drag object and frees all allocated resources.
*/


qt'QImageDrag::~QImageDrag() (./qt-2.1.0/src/kernel/qdragobject.cpp:774)

QImageDrag::~QImageDrag()
{
    // nothing
}


/*!
  Sets the image to be dragged.  You will need to call this if you did
  not pass the image during construction.
*/

qt'QImageDrag::setImage() (./qt-2.1.0/src/kernel/qdragobject.cpp:784)

void QImageDrag::setImage( QImage image )
{
    img = image; // ### detach?
    ofmts = QImage::outputFormats();
    ofmts.remove("PBM"); // remove non-raw PPM
    if ( image.depth()!=32 ) {
	// BMP better than PPM for paletted images
	if ( ofmts.remove("BMP") ) // move to front
	    ofmts.insert(0,"BMP");
    }
    // PNG is best of all
    if ( ofmts.remove("PNG") ) // move to front
	ofmts.insert(0,"PNG");
}

/*!
  \reimp
*/

qt'QImageDrag::format() (./qt-2.1.0/src/kernel/qdragobject.cpp:802)

const char * QImageDrag::format(int i) const
{
    if ( i < (int)ofmts.count() ) {
	static QCString str;
	str.sprintf("image/%s",(((QImageDrag*)this)->ofmts).at(i));
	str = str.lower();
	if ( str == "image/pbmraw" )
	    str = "image/ppm";
	return str;
    } else {
	return 0;
    }
}

/*!
  \reimp
*/

qt'QImageDrag::encodedData() (./qt-2.1.0/src/kernel/qdragobject.cpp:819)

QByteArray QImageDrag::encodedData(const char* fmt) const
{
    if ( qstrnicmp( fmt, "image/", 6 )==0 ) {
	QCString f = fmt+6;
	QByteArray data;
	QBuffer w( data );
	w.open( IO_WriteOnly );
	QImageIO io( &w, f.upper() );
	io.setImage( img );
	if  ( !io.write() )
	    return QByteArray();
	w.close();
	return data;
    } else {
	return QByteArray();
    }
}

/*!
  Returns TRUE if the information in \a e can be decoded into an image.
  \sa decode()
*/

qt'QImageDrag::canDecode() (./qt-2.1.0/src/kernel/qdragobject.cpp:841)

bool QImageDrag::canDecode( const QMimeSource* e )
{
    QStrList fileFormats = QImageIO::inputFormats();
    fileFormats.first();
    while ( fileFormats.current() ) {
	QCString format = fileFormats.current();
	QCString type = "image/" + format.lower();
	if ( e->provides( type.data() ) )
	    return TRUE;
	fileFormats.next();
    }
    return FALSE;
}

/*!
  Attempts to decode the dropped information in \a e
  into \a img, returning TRUE if successful.

  \sa canDecode()
*/

qt'QImageDrag::decode() (./qt-2.1.0/src/kernel/qdragobject.cpp:861)

bool QImageDrag::decode( const QMimeSource* e, QImage& img )
{
    QByteArray payload;
    QStrList fileFormats = QImageIO::inputFormats();
    // PNG is best of all
    if ( fileFormats.remove("PNG") ) // move to front
	fileFormats.insert(0,"PNG");
    fileFormats.first();
    while ( fileFormats.current() ) {
	QCString format = fileFormats.current();
	QCString type = "image/" + format.lower();
	payload = e->encodedData( type.data() );
	if ( !payload.isEmpty() )
	    break;
	fileFormats.next();
    }

    if ( payload.isEmpty() )
	return FALSE;

    img.loadFromData(payload);
    return !img.isNull();
}

/*!
  Attempts to decode the dropped information in \a e
  into \a pm, returning TRUE if successful.

  This is a convenience function that converts
  to \a pm via a QImage.

  \sa canDecode()
*/

qt'QImageDrag::decode() (./qt-2.1.0/src/kernel/qdragobject.cpp:894)

bool QImageDrag::decode( const QMimeSource* e, QPixmap& pm )
{
    QImage img;
    // We avoid dither, since the image probably came from this display
    if ( decode( e, img ) )
	return pm.convertFromImage( img, AvoidDither );
    return FALSE;
}




/*!
  \class QStoredDrag qdragobject.h
  \brief Simple stored-value drag object for arbitrary MIME data.

  When a block of data only has one representation, you can use
  a QStoredDrag to hold it.

  For detailed information about drag-and-drop, see the QDragObject class.
*/

/*!
  Constructs a QStoredDrag.  The parameters are passed
  to the QDragObject constructor, and the format is set to \a mimeType.

  The data will be unset.  Use setEncodedData() to set it.
*/