3
0
mirror of https://github.com/Qortal/Brooklyn.git synced 2025-02-07 06:44:18 +00:00
Brooklyn/plasma/workspace/klipper/historyimageitem.cpp
2022-04-02 18:24:21 +05:00

64 lines
1.3 KiB
C++

/*
SPDX-FileCopyrightText: 2004 Esben Mose Hansen <kde@mosehansen.dk>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "historyimageitem.h"
#include "historymodel.h"
#include <QCryptographicHash>
#include <QIcon>
#include <QMimeData>
#include <KLocalizedString>
namespace
{
QByteArray compute_uuid(const QPixmap &data)
{
QByteArray buffer;
QDataStream out(&buffer, QIODevice::WriteOnly);
out << data;
return QCryptographicHash::hash(buffer, QCryptographicHash::Sha1);
}
}
HistoryImageItem::HistoryImageItem(const QPixmap &data)
: HistoryItem(compute_uuid(data))
, m_data(data)
{
}
QString HistoryImageItem::text() const
{
if (m_text.isNull()) {
m_text = QStringLiteral("") + i18n("%1x%2 %3bpp", m_data.width(), m_data.height(), m_data.depth());
}
return m_text;
}
/* virtual */
void HistoryImageItem::write(QDataStream &stream) const
{
stream << QStringLiteral("image") << m_data;
}
QMimeData *HistoryImageItem::mimeData() const
{
QMimeData *data = new QMimeData();
data->setImageData(m_data.toImage());
return data;
}
const QPixmap &HistoryImageItem::image() const
{
if (m_model->displayImages()) {
return m_data;
}
static QPixmap imageIcon(QIcon::fromTheme(QStringLiteral("view-preview")).pixmap(QSize(48, 48)));
return imageIcon;
}