2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-18 09:50:21 +11:00
|
|
|
// The Clipboard class exposes system clipboard management and retrieval
|
|
|
|
// to QML.
|
|
|
|
|
2019-10-25 23:36:24 +11:00
|
|
|
#ifndef CLIPBOARD_H
|
|
|
|
#define CLIPBOARD_H
|
|
|
|
|
|
|
|
#include <QGuiApplication>
|
2020-06-13 04:10:11 +10:00
|
|
|
#include <QClipboard>
|
2019-10-25 23:36:24 +11:00
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
|
|
class Clipboard : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
|
|
|
Q_PROPERTY(QString selection READ selection WRITE setSelection
|
|
|
|
NOTIFY selectionChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(bool supportsSelection READ supportsSelection CONSTANT)
|
|
|
|
|
|
|
|
public:
|
2020-06-13 04:10:11 +10:00
|
|
|
explicit Clipboard(QObject *parent = nullptr) : QObject(parent) {
|
|
|
|
connect(this->clipboard, &QClipboard::dataChanged,
|
|
|
|
this, &Clipboard::textChanged);
|
|
|
|
|
|
|
|
connect(this->clipboard, &QClipboard::selectionChanged,
|
|
|
|
this, &Clipboard::selectionChanged);
|
|
|
|
}
|
2019-10-25 23:36:24 +11:00
|
|
|
|
2019-12-18 09:50:21 +11:00
|
|
|
// Normal primary clipboard
|
2020-06-13 04:10:11 +10:00
|
|
|
|
|
|
|
QString text() const {
|
|
|
|
return this->clipboard->text(QClipboard::Clipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setText(const QString &text) const {
|
|
|
|
this->clipboard->setText(text, QClipboard::Clipboard);
|
|
|
|
}
|
2019-10-25 23:36:24 +11:00
|
|
|
|
2019-12-18 09:50:21 +11:00
|
|
|
// X11 select-middle-click-paste clipboard
|
2019-10-25 23:36:24 +11:00
|
|
|
|
2020-06-13 04:10:11 +10:00
|
|
|
QString selection() const {
|
|
|
|
return this->clipboard->text(QClipboard::Selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSelection(const QString &text) const {
|
|
|
|
if (this->clipboard->supportsSelection()) {
|
|
|
|
this->clipboard->setText(text, QClipboard::Selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Info
|
|
|
|
|
|
|
|
bool supportsSelection() const {
|
|
|
|
return this->clipboard->supportsSelection();
|
|
|
|
}
|
2019-10-25 23:36:24 +11:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void textChanged();
|
|
|
|
void selectionChanged();
|
|
|
|
|
|
|
|
private:
|
2020-06-13 04:10:11 +10:00
|
|
|
QClipboard *clipboard = QGuiApplication::clipboard();
|
2019-10-25 23:36:24 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|