Skip to content

Commit

Permalink
added onClipboardChange
Browse files Browse the repository at this point in the history
  • Loading branch information
relipse committed Sep 11, 2013
1 parent 330c2ce commit 61b7045
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
38 changes: 38 additions & 0 deletions jsrclipboardchange.cpp
@@ -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);
}
21 changes: 21 additions & 0 deletions jsrclipboardchange.h
@@ -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

0 comments on commit 61b7045

Please sign in to comment.