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

Class Index

qt'QColorDrag (./qt-2.1.0/src/kernel/qdragobject.h:153)

class QColorDrag : public QStoredDrag
{
    Q_OBJECT
    QColor color;

public:
    QColorDrag( const QColor &col, QWidget *dragsource = 0, const char *name = 0 );
    QColorDrag( QWidget * dragSource = 0, const char * name = 0 );
    void setColor( const QColor &col );

    static bool canDecode( QMimeSource * );
    static bool decode( QMimeSource *, QColor &col );
};

qt'QColorDrag::QColorDrag() (./qt-2.1.0/src/kernel/qdragobject.cpp:1330)

QColorDrag::QColorDrag( const QColor &col, QWidget *dragsource, const char *name )
    : QStoredDrag( "application/x-color", dragsource, name )
{
    setColor( col );
}

/*!
  Constructs a color drag with a while color
*/


qt'QColorDrag::QColorDrag() (./qt-2.1.0/src/kernel/qdragobject.cpp:1340)

QColorDrag::QColorDrag( QWidget *dragsource, const char *name )
    : QStoredDrag( "application/x-color", dragsource, name )
{
    setColor( Qt::white );
}

/*!
  Sets the color of the color drag to \a col
*/


qt'QColorDrag::setColor() (./qt-2.1.0/src/kernel/qdragobject.cpp:1350)

void QColorDrag::setColor( const QColor &col )
{
    QByteArray data;
    ushort rgba[ 4 ];
    data.resize( sizeof( rgba ) );
    rgba[ 0 ] = col.red()  * 0xFF;
    rgba[ 1 ] = col.green() * 0xFF;
    rgba[ 2 ] = col.blue()  * 0xFF;
    rgba[ 3 ] = 0xFFFF; // Alpha not supported yet.
    memcpy( data.data(), rgba, sizeof( rgba) );
    setEncodedData( data );
}

/*!
  Returns TRUE, if the color drag object can decode the
  mime source \a e.
*/


qt'QColorDrag::canDecode() (./qt-2.1.0/src/kernel/qdragobject.cpp:1368)

bool QColorDrag::canDecode( QMimeSource *e )
{
    return e->provides( "application/x-color" );
}

/*!
  Decodes the mime source \a e and sets the decoded values to \a col.
*/


qt'QColorDrag::decode() (./qt-2.1.0/src/kernel/qdragobject.cpp:1377)

bool QColorDrag::decode( QMimeSource *e, QColor &col )
{
    QByteArray data = e->encodedData( "application/x-color" );
    ushort rgba[ 4 ];
    if( data.size() != sizeof( rgba ) )
	return FALSE;
    memcpy( rgba, data.data(), sizeof( rgba ) );
    col.setRgb( rgba[ 0 ] / 0xFF, rgba[ 1 ] / 0xFF, rgba[ 2 ] / 0xFF );
    return TRUE;
}