23 #include <QtCore/QBuffer>
24 #include <QtCore/QSharedData>
28 class PicturePrivate :
public QSharedData
36 PicturePrivate(
const PicturePrivate &other )
37 : QSharedData( other )
42 mIntern = other.mIntern;
48 mutable QByteArray mRawData;
55 Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<KABC::PicturePrivate>, s_sharedEmpty, (
new KABC::PicturePrivate))
60 : d( *s_sharedEmpty() )
64 Picture::Picture(
const QString &url )
65 : d( new PicturePrivate )
71 : d( new PicturePrivate )
87 if (
this != &other ) {
96 if ( d->mIntern != p.d->mIntern ) {
100 if ( d->mType != p.d->mType ) {
105 if ( !d->mData.isNull() && !p.d->mData.isNull() ) {
106 if ( d->mData != p.d->mData ) {
109 }
else if ( !d->mRawData.isEmpty() && !p.d->mRawData.isEmpty() ) {
110 if ( d->mRawData != p.d->mRawData ) {
113 }
else if ( ( !d->mData.isNull() || !d->mRawData.isEmpty() ) &&
114 ( !p.d->mData.isNull() || !p.d->mRawData.isEmpty() ) ) {
123 if ( d->mUrl != p.d->mUrl ) {
133 return !( p == *this );
139 ( ( d->mIntern ==
false && d->mUrl.isEmpty() ) ||
140 ( d->mIntern ==
true && d->mData.isNull() && d->mRawData.isEmpty() ) );
164 if ( !d->mData.hasAlphaChannel() ) {
165 d->mType = QLatin1String(
"jpeg" );
167 d->mType = QLatin1String(
"png" );
196 if ( d->mData.isNull() && !d->mRawData.isEmpty() ) {
197 d->mData.loadFromData( d->mRawData );
205 if ( d->mRawData.isEmpty() && !d->mData.isNull() ) {
206 QBuffer buffer( &d->mRawData );
207 buffer.open( QIODevice::WriteOnly );
210 d->mData.save( &buffer, d->mType.toUpper().toLatin1().data() );
225 str += QLatin1String(
"Picture {\n" );
226 str += QString::fromLatin1(
" Type: %1\n" ).arg( d->mType );
227 str += QString::fromLatin1(
" IsIntern: %1\n" ).
228 arg( d->mIntern ? QLatin1String(
"true" ) : QLatin1String(
"false" ) );
230 str += QString::fromLatin1(
" Data: %1\n" ).arg( QString::fromLatin1(
rawData().toBase64() ) );
232 str += QString::fromLatin1(
" Url: %1\n" ).arg( d->mUrl );
234 str += QLatin1String(
"}\n" );
239 QDataStream &KABC::operator<<( QDataStream &s,
const Picture &picture )
241 return s << picture.d->mIntern << picture.d->mUrl << picture.d->mType << picture.
data();
244 QDataStream &KABC::operator>>( QDataStream &s,
Picture &picture )
246 s >> picture.d->mIntern >> picture.d->mUrl >> picture.d->mType >> picture.d->mData;
A class to store a picture of an addressee.
void KABC_DEPRECATED setType(const QString &type)
Sets the type of the picture.
Picture & operator=(const Picture &other)
Assignment operator.
QString toString() const
Returns string representation of the picture.
QByteArray rawData() const
Returns the raw data of this picture.
void setRawData(const QByteArray &rawData, const QString &type)
Sets the raw data of the picture.
QString url() const
Returns the location URL of this picture.
QImage data() const
Returns the image data of this picture.
void setData(const QImage &data)
Sets the image data of the picture.
bool isEmpty() const
Returns true, if the picture is empty.
bool operator==(const Picture &) const
Equality operator.
QString type() const
Returns the type of this picture.
bool operator!=(const Picture &) const
Not-Equal operator.
void setUrl(const QString &url)
Sets a URL for the location of the picture file.
bool isIntern() const
Returns whether the picture is described by a URL (extern) or by the raw data (intern).
Picture()
Creates an empty picture.