diff options
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/clipboard/capi.hpp | 11 | ||||
-rw-r--r-- | ui/qt/clipboard/clipboard.cpp | 20 | ||||
-rw-r--r-- | ui/qt/clipboard/clipboard.go | 15 | ||||
-rw-r--r-- | ui/qt/clipboard/clipboard.hpp | 23 |
4 files changed, 69 insertions, 0 deletions
diff --git a/ui/qt/clipboard/capi.hpp b/ui/qt/clipboard/capi.hpp new file mode 100644 index 000000000..202613469 --- /dev/null +++ b/ui/qt/clipboard/capi.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "clipboard.hpp" + +typedef void Clipboard_; + +Clipboard_ *initClipboard() +{ + Clipboard *clipboard = new(Clipboard); + return static_cast<Clipboard_*>(clipboard); +} diff --git a/ui/qt/clipboard/clipboard.cpp b/ui/qt/clipboard/clipboard.cpp new file mode 100644 index 000000000..192aa7a2b --- /dev/null +++ b/ui/qt/clipboard/clipboard.cpp @@ -0,0 +1,20 @@ +#include "clipboard.h" + +#include <QClipboard> + +Clipboard::Clipboard() +{ + connect(QApplication::clipboard(), &QClipboard::dataChanged, [this] { emit clipboardChanged();}); +} + +QString Clipboard::get() const +{ + QClipboard *clipboard = QApplication::clipboard(); + return clipboard->text(); +} + +void Clipboard::toClipboard(QString _text) +{ + QClipboard *clipboard = QApplicationion::clipboard(); + clipboard->setText(_text); +} diff --git a/ui/qt/clipboard/clipboard.go b/ui/qt/clipboard/clipboard.go new file mode 100644 index 000000000..064ee954d --- /dev/null +++ b/ui/qt/clipboard/clipboard.go @@ -0,0 +1,15 @@ +package clipboard + +// #cgo CPPFLAGS: -I./ +// #cgo CXXFLAGS: -std=c++0x -pedantic-errors -Wall -fno-strict-aliasing +// #cgo LDFLAGS: -lstdc++ +// #cgo pkg-config: Qt5Quick +// +// #include "capi.hpp" +import "C" + +import "github.com/obscuren/qml" + +func SetQMLClipboard(context *qml.Context) { + context.SetVar("clipboard", (unsafe.Pointer)(C.initClipboard())) +} diff --git a/ui/qt/clipboard/clipboard.hpp b/ui/qt/clipboard/clipboard.hpp new file mode 100644 index 000000000..1aa213ceb --- /dev/null +++ b/ui/qt/clipboard/clipboard.hpp @@ -0,0 +1,23 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +class Clipboard : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString get READ get WRITE toClipboard NOTIFY clipboardChanged) +public: + Clipboard(); + virtual ~Clipboard(){} + + Q_INVOKABLE void toClipboard(QString _text); + +signals: + void clipboardChanged(); +}; + +#ifdef __cplusplus +} // extern "C" +#endif |