Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "jsrclipboardchange.h" | ||
|
||
#include <QApplication> | ||
#include <QMimeData> | ||
|
||
|
||
JSRClipboardChange::JSRClipboardChange(QJSEngine *pengine, QJSValue callback) | ||
: JSCallback(pengine, callback) | ||
{ | ||
//do nothing | ||
} | ||
|
||
bool JSRClipboardChange::exec() | ||
{ | ||
m_clipboard = QApplication::clipboard(); | ||
connect(m_clipboard, SIGNAL(changed(QClipboard::Mode)),this,SLOT(changedSlot(QClipboard::Mode))); | ||
return true; | ||
} | ||
|
||
|
||
|
||
|
||
void JSRClipboardChange::changedSlot(QClipboard::Mode mode) | ||
{ | ||
//TODO: support images and other cool stuff like html, images, urls etc... @see QMimeData | ||
QJSValueList args; | ||
if(QApplication::clipboard()->mimeData()->hasText()) | ||
{ | ||
QString data = m_clipboard->text(); | ||
args.push_back(QJSValue(data)); | ||
} | ||
|
||
call(args); | ||
|
||
//emit a signal that our callback was completed, technically we should be able to | ||
//delete the object but i'm not sure if we have to wait a little bit | ||
emit callbackCompleted(this, m_callbackResult); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef JSRCLIPBOARDCHANGE_H | ||
#define JSRCLIPBOARDCHANGE_H | ||
|
||
#include "jscallback.h" | ||
|
||
#include <QClipboard> | ||
|
||
class JSRClipboardChange : public JSCallback | ||
{ | ||
Q_OBJECT | ||
public: | ||
JSRClipboardChange(QJSEngine* pengine, QJSValue callback); | ||
bool exec(); | ||
public slots: | ||
void changedSlot(QClipboard::Mode mode); | ||
|
||
protected: | ||
QClipboard* m_clipboard; | ||
}; | ||
|
||
#endif // JSRCLIPBOARDCHANGE_H |