Permit opening subwindow from js with SkyliveX object working

parent 018ad60b
function skyliveClass () {}
skyliveClass.prototype.method = function(name, func){
this.prototype[name] = func;
return this;
}
skyliveClass.method('changeContent', function(id, content){
skyliveClass.prototype.changeContent = function(id, content){
var n=document.getElementById(id);
if(typeof(n)!="undefined")
n.innerHTML=content;
});
skyliveClass.method('notify', function(content){
};
skyliveClass.prototype.notify = function(content){
if(typeof(notifycb)=="function")
notifycb(content);
});
skyliveClass.method('msgalert', function(content){
};
skyliveClass.prototype.msgalert = function(content){
if(typeof(alertcb)=="function")
alertcb(content);
//else
// alert(content);
});
skyliveClass.method('publicReceived', function(user, msg){
};
skyliveClass.prototype.publicReceived = function(user, msg){
if(typeof(public_received)=="function")
{
public_received(user, msg);
......@@ -32,9 +28,10 @@ skyliveClass.method('publicReceived', function(user, msg){
n.scollTop = n.scrollHeight;
}
}
});
SkyliveX.page = new SkyliveClass();
SkyliveX.changeContent.connect(SkyliveX.page.changeContent);
SkyliveX.notify.connect(SkyliveX.page.notify);
SkyliveX.alertmsg.connect(SkyliveX.page.msgalert);
SkyliveX.public_received.connect(SkyliveX.page.publicReceived);
};
SkyliveXPage = new skyliveClass();
SkyliveX.changeContent.connect(SkyliveXPage.changeContent);
SkyliveX.notify.connect(SkyliveXPage.notify);
SkyliveX.alertmsg.connect(SkyliveXPage.msgalert);
SkyliveX.public_received.connect(SkyliveXPage.publicReceived);
......@@ -34,6 +34,7 @@
*/
#include "webwin.h"
#include <QWebView>
#include <QWebPage>
#include <QWebFrame>
#include <QFile>
#include <QUrl>
......@@ -44,6 +45,7 @@
#include <iostream>
#include "ipcmsg.h"
#include "jsbridge.h"
#include "QWebSettings"
#define SENDER "webwin"
......@@ -52,6 +54,10 @@ WebWin::WebWin(QString &htmlfile)
{
baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("gui/dummy.html"));
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
//settings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
QPalette pal = palette();
pal.setBrush(QPalette::Base, Qt::transparent);
......@@ -74,11 +80,43 @@ WebWin::WebWin(QString &htmlfile)
}
WebWin::WebWin()
: QWebView()
{
baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("gui/dummy.html"));
settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
jsbridge = new JSBridge();
jsbridge->wwin = qobject_cast<WebWin *>(this);
page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", jsbridge);
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(refreshJsObject()));
msgsender = SENDER;
}
WebWin::~WebWin()
{
}
QWebView* WebWin::createWindow(QWebPage::WebWindowType type)
{
WebWin *wv = new WebWin;
QWebPage *newWeb = new QWebPage(wv);
wv->jsbridge = new JSBridge();
newWeb->mainFrame()->addToJavaScriptWindowObject("SkyliveX", wv->jsbridge);
connect(newWeb->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), wv, SLOT(refreshJsObject()));
wv->setPage(newWeb);
wv->setAttribute(Qt::WA_DeleteOnClose, true);
if (type == QWebPage::WebModalDialog)
wv->setWindowModality(Qt::ApplicationModal);
wv->show();
return wv;
}
// XXX This can be used in future to permit
// to drag a window borderless on the desktop.
/*
......
......@@ -36,6 +36,7 @@
#define WEBWIN_H
#include <QWebView>
#include <QWebPage>
#include <QUrl>
#include <QFile>
#include <QHash>
......@@ -69,6 +70,7 @@ class WebWin : public QWebView
QHash<QString, SKHandlerFunction> _handlers;
public:
WebWin();
WebWin(QString &htmlfile);
~WebWin();
void setHtmlFile(QString &fname);
......@@ -78,6 +80,7 @@ class WebWin : public QWebView
void registerHandler(QString type, SKHandlerFunction handler);
void toggleBorders(bool borders);
void toggleTransparentBackground(bool transparentbg);
QWebView* createWindow(QWebPage::WebWindowType type);
JSBridge* jsbridge;
QString msgsender;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment