History

Rename WebWindow to WebWindowClass

Ryan Huffman committed 12 years ago

Commit a1d771a1 parent bd61eba3 files · +19 −19Browse files

Showing the changes to interface/src/scripting/WebWindowClass.cpp (1 of 3 files). Show all

Unified · Split

interface/src/scripting/WebWindowClass.cpp+68−0
@@ -0,0 +1,68 @@
1//
2// WebWindowClass.cpp
3// interface/src/scripting
4//
5// Created by Ryan Huffman on 11/06/14.
6// Copyright 2014 High Fidelity, Inc.
7//
8// Distributed under the Apache License, Version 2.0.
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10//
11
12#include <QVBoxLayout>
13#include <QApplication>
14#include <QWebFrame>
15#include <QWebView>
16
17#include "WindowScriptingInterface.h"
18#include "WebWindowClass.h"
19
20ScriptEventBridge::ScriptEventBridge(QObject* parent) : QObject(parent) {
21}
22
23void ScriptEventBridge::emitWebEvent(const QString& data) {
24 emit webEventReceived(data);
25}
26
27void ScriptEventBridge::emitScriptEvent(const QString& data) {
28 emit scriptEventReceived(data);
29}
30
31WebWindowClass::WebWindowClass(const QString& url, int width, int height)
32 : QObject(NULL),
33 _window(new QWidget(NULL, Qt::Tool)),
34 _eventBridge(new ScriptEventBridge(this)) {
35
36 QWebView* webView = new QWebView(_window);
37 webView->page()->mainFrame()->addToJavaScriptWindowObject("EventBridge", _eventBridge);
38 webView->setUrl(url);
39 QVBoxLayout* layout = new QVBoxLayout(_window);
40 _window->setLayout(layout);
41 layout->addWidget(webView);
42 layout->setSpacing(0);
43 layout->setContentsMargins(0, 0, 0, 0);
44 _window->setGeometry(0, 0, width, height);
45
46 connect(this, &WebWindowClass::destroyed, _window, &QWidget::deleteLater);
47}
48
49WebWindowClass::~WebWindowClass() {
50}
51
52void WebWindowClass::setVisible(bool visible) {
53 QMetaObject::invokeMethod(_window, "setVisible", Qt::BlockingQueuedConnection, Q_ARG(bool, visible));
54}
55
56QScriptValue WebWindowClass::constructor(QScriptContext* context, QScriptEngine* engine) {
57 WebWindowClass* retVal;
58 QString file = context->argument(0).toString();
59 QMetaObject::invokeMethod(WindowScriptingInterface::getInstance(), "doCreateWebWindowClass", Qt::BlockingQueuedConnection,
60 Q_RETURN_ARG(WebWindowClass*, retVal),
61 Q_ARG(const QString&, file),
62 Q_ARG(int, context->argument(1).toInteger()),
63 Q_ARG(int, context->argument(2).toInteger()));
64
65 connect(engine, &QScriptEngine::destroyed, retVal, &WebWindowClass::deleteLater);
66
67 return engine->newQObject(retVal);//, QScriptEngine::ScriptOwnership);
68}