2020-09-24 09:57:54 +10:00
|
|
|
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
|
2020-07-17 03:54:17 +10:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
#ifndef CLIPBOARD_IMAGE_PROVIDER_H
|
|
|
|
#define CLIPBOARD_IMAGE_PROVIDER_H
|
|
|
|
|
|
|
|
#include <QImage>
|
|
|
|
#include <QQuickImageProvider>
|
|
|
|
|
2020-07-17 05:15:10 +10:00
|
|
|
#include "clipboard.h"
|
2020-07-17 03:54:17 +10:00
|
|
|
|
|
|
|
|
2020-07-17 05:15:10 +10:00
|
|
|
class ClipboardImageProvider : public QQuickImageProvider {
|
2020-07-17 03:54:17 +10:00
|
|
|
public:
|
2020-07-17 05:15:10 +10:00
|
|
|
explicit ClipboardImageProvider(Clipboard *clipboard)
|
|
|
|
: QQuickImageProvider(QQuickImageProvider::Image)
|
|
|
|
{
|
|
|
|
this->clipboard = clipboard;
|
|
|
|
}
|
2020-07-17 03:54:17 +10:00
|
|
|
|
|
|
|
QImage requestImage(
|
|
|
|
const QString &id, QSize *size, const QSize &requestSize
|
|
|
|
) {
|
|
|
|
Q_UNUSED(id);
|
|
|
|
|
2020-07-17 05:15:10 +10:00
|
|
|
QImage *image = this->clipboard->qimage();
|
2020-07-17 03:54:17 +10:00
|
|
|
|
2020-07-17 05:15:10 +10:00
|
|
|
if (size) *size = image->size();
|
2020-07-17 03:54:17 +10:00
|
|
|
|
|
|
|
if (requestSize.width() > 0 && requestSize.height() > 0)
|
2020-07-17 05:15:10 +10:00
|
|
|
return image->scaled(
|
2020-07-17 03:54:17 +10:00
|
|
|
requestSize.width(), requestSize.height(), Qt::KeepAspectRatio
|
|
|
|
);
|
|
|
|
|
2020-07-17 05:15:10 +10:00
|
|
|
return *image;
|
2020-07-17 03:54:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-07-17 05:15:10 +10:00
|
|
|
Clipboard *clipboard;
|
2020-07-17 03:54:17 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|