File indexing completed on 2024-04-28 05:35:28
0001 /* 0002 SPDX-FileCopyrightText: 2004 Esben Mose Hansen <kde@mosehansen.dk> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "historyimageitem.h" 0008 0009 #include "historymodel.h" 0010 0011 #include <QCryptographicHash> 0012 #include <QIODevice> 0013 #include <QIcon> 0014 #include <QMimeData> 0015 0016 #include <KLocalizedString> 0017 0018 namespace 0019 { 0020 QByteArray compute_uuid(const QImage &data) 0021 { 0022 return QCryptographicHash::hash(QByteArray::fromRawData(reinterpret_cast<const char *>(data.constBits()), data.sizeInBytes()), QCryptographicHash::Sha1); 0023 } 0024 0025 } 0026 0027 HistoryImageItem::HistoryImageItem(const QImage &data) 0028 : HistoryItem(compute_uuid(data)) 0029 , m_data(data) 0030 { 0031 } 0032 0033 QString HistoryImageItem::text() const 0034 { 0035 if (m_text.isNull()) { 0036 m_text = QStringLiteral("▨ ") + i18n("%1x%2 %3bpp", m_data.width(), m_data.height(), m_data.depth()); 0037 } 0038 return m_text; 0039 } 0040 0041 /* virtual */ 0042 void HistoryImageItem::write(QDataStream &stream) const 0043 { 0044 stream << QStringLiteral("image") << m_data; 0045 } 0046 0047 QMimeData *HistoryImageItem::mimeData() const 0048 { 0049 QMimeData *data = new QMimeData(); 0050 data->setImageData(m_data); 0051 return data; 0052 } 0053 0054 QImage HistoryImageItem::image() const 0055 { 0056 if (m_model->displayImages()) { 0057 return m_data; 0058 } 0059 static const QImage imageIcon(QIcon::fromTheme(QStringLiteral("view-preview")).pixmap(QSize(48, 48)).toImage()); 0060 return imageIcon; 0061 }