1/* This file is part of the KDE project
2 Copyright (C) 2004 Esben Mose Hansen <kde@mosehansen.dk>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19#include "historyimageitem.h"
20
21#include <QtCore/QMimeData>
22#include <QtCore/QCryptographicHash>
23
24#include <KDebug>
25
26namespace {
27 QByteArray compute_uuid(const QPixmap& data) {
28 QByteArray buffer;
29 QDataStream out(&buffer, QIODevice::WriteOnly);
30 out << data;
31 return QCryptographicHash::hash(buffer, QCryptographicHash::Sha1);
32 }
33
34}
35
36HistoryImageItem::HistoryImageItem( const QPixmap& data )
37 : HistoryItem(compute_uuid(data))
38 , m_data( data )
39{
40}
41
42QString HistoryImageItem::text() const {
43 if ( m_text.isNull() ) {
44 m_text = QString( "%1x%2x%3 %4" )
45 .arg( m_data.width() )
46 .arg( m_data.height() )
47 .arg( m_data.depth() );
48 }
49 return m_text;
50
51}
52
53/* virtual */
54void HistoryImageItem::write( QDataStream& stream ) const {
55 stream << QString( "image" ) << m_data;
56}
57
58QMimeData* HistoryImageItem::mimeData() const
59{
60 QMimeData *data = new QMimeData();
61 data->setImageData(m_data.toImage());
62 return data;
63}
64
65