Showing the changes to interface/src/scripting/WebWindowClass.cpp (1 of 37 files). Show all
Unified · Split
| @@ -9,6 +9,7 @@ · 8 unmodified lines | |||
| 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 10 | // | 10 | // |
| 11 | 11 | ||
| 12 | |||
| 12 | #include <QVBoxLayout> | 13 | #include <QVBoxLayout> |
| 13 | #include <QApplication> | 14 | #include <QApplication> |
| 14 | #include <QMainWindow> | 15 | #include <QMainWindow> |
| @@ -35,48 +36,25 @@ void ScriptEventBridge::emitScriptEvent(const QString& data) { · 20 unmodified lines | |||
| 35 | emit scriptEventReceived(data); | 36 | emit scriptEventReceived(data); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | WebWindowClass::WebWindowClass(const QString& title, const QString& url, int width, int height, bool isToolWindow) | 39 | WebWindowClass::WebWindowClass(const QString& title, const QString& url, int width, int height) |
| 39 | : QObject(NULL), | 40 | : QObject(NULL), _eventBridge(new ScriptEventBridge(this)) { |
| 40 | _eventBridge(new ScriptEventBridge(this)), | 41 | auto dialogWidget = new QDialog(qApp->getWindow(), Qt::Window); |
| 41 | _isToolWindow(isToolWindow) { | 42 | dialogWidget->setWindowTitle(title); |
| 42 | 43 | dialogWidget->resize(width, height); | |
| 43 | if (_isToolWindow) { | 44 | dialogWidget->installEventFilter(this); |
| 44 | ToolWindow* toolWindow = qApp->getToolWindow(); | 45 | connect(dialogWidget, &QDialog::finished, this, &WebWindowClass::hasClosed); |
| 45 | |||
| 46 | auto dockWidget = new QDockWidget(title, toolWindow); | ||
| 47 | dockWidget->setFeatures(QDockWidget::DockWidgetMovable); | ||
| 48 | connect(dockWidget, &QDockWidget::visibilityChanged, this, &WebWindowClass::visibilityChanged); | ||
| 49 | |||
| 50 | _webView = new QWebView(dockWidget); | ||
| 51 | addEventBridgeToWindowObject(); | ||
| 52 | 46 | ||
| 53 | dockWidget->setWidget(_webView); | 47 | auto layout = new QVBoxLayout(dialogWidget); |
| 48 | layout->setContentsMargins(0, 0, 0, 0); | ||
| 49 | dialogWidget->setLayout(layout); | ||
| 54 | 50 | ||
| 55 | auto titleWidget = new QWidget(dockWidget); | 51 | _webView = new QWebView(dialogWidget); |
| 56 | dockWidget->setTitleBarWidget(titleWidget); | ||
| 57 | |||
| 58 | toolWindow->addDockWidget(Qt::TopDockWidgetArea, dockWidget, Qt::Horizontal); | ||
| 59 | |||
| 60 | _windowWidget = dockWidget; | ||
| 61 | } else { | ||
| 62 | auto dialogWidget = new QDialog(qApp->getWindow(), Qt::Window); | ||
| 63 | dialogWidget->setWindowTitle(title); | ||
| 64 | dialogWidget->resize(width, height); | ||
| 65 | dialogWidget->installEventFilter(this); | ||
| 66 | connect(dialogWidget, &QDialog::finished, this, &WebWindowClass::hasClosed); | ||
| 67 | 52 | ||
| 68 | auto layout = new QVBoxLayout(dialogWidget); | 53 | layout->addWidget(_webView); |
| 69 | layout->setContentsMargins(0, 0, 0, 0); | ||
| 70 | dialogWidget->setLayout(layout); | ||
| 71 | 54 | ||
| 72 | _webView = new QWebView(dialogWidget); | 55 | addEventBridgeToWindowObject(); |
| 73 | 56 | ||
| 74 | layout->addWidget(_webView); | 57 | _windowWidget = dialogWidget; |
| 75 | |||
| 76 | addEventBridgeToWindowObject(); | ||
| 77 | |||
| 78 | _windowWidget = dialogWidget; | ||
| 79 | } | ||
| 80 | 58 | ||
| 81 | auto style = QStyleFactory::create("fusion"); | 59 | auto style = QStyleFactory::create("fusion"); |
| 82 | if (style) { | 60 | if (style) { |
| @@ -121,13 +99,8 @@ void WebWindowClass::addEventBridgeToWindowObject() { · 38 unmodified lines | |||
| 121 | 99 | ||
| 122 | void WebWindowClass::setVisible(bool visible) { | 100 | void WebWindowClass::setVisible(bool visible) { |
| 123 | if (visible) { | 101 | if (visible) { |
| 124 | if (_isToolWindow) { | 102 | QMetaObject::invokeMethod(_windowWidget, "showNormal", Qt::AutoConnection); |
| 125 | QMetaObject::invokeMethod( | 103 | QMetaObject::invokeMethod(_windowWidget, "raise", Qt::AutoConnection); |
| 126 | qApp->getToolWindow(), "setVisible", Qt::AutoConnection, Q_ARG(bool, visible)); | ||
| 127 | } else { | ||
| 128 | QMetaObject::invokeMethod(_windowWidget, "showNormal", Qt::AutoConnection); | ||
| 129 | QMetaObject::invokeMethod(_windowWidget, "raise", Qt::AutoConnection); | ||
| 130 | } | ||
| 131 | } | 104 | } |
| 132 | QMetaObject::invokeMethod(_windowWidget, "setVisible", Qt::AutoConnection, Q_ARG(bool, visible)); | 105 | QMetaObject::invokeMethod(_windowWidget, "setVisible", Qt::AutoConnection, Q_ARG(bool, visible)); |
| 133 | } | 106 | } |
| @@ -182,13 +155,18 @@ void WebWindowClass::raise() { · 48 unmodified lines | |||
| 182 | QScriptValue WebWindowClass::constructor(QScriptContext* context, QScriptEngine* engine) { | 155 | QScriptValue WebWindowClass::constructor(QScriptContext* context, QScriptEngine* engine) { |
| 183 | WebWindowClass* retVal; | 156 | WebWindowClass* retVal; |
| 184 | QString file = context->argument(0).toString(); | 157 | QString file = context->argument(0).toString(); |
| 158 | if (context->argument(4).toBool()) { | ||
| 159 | qWarning() << "ToolWindow views with WebWindow are no longer supported. Use OverlayWebWindow instead"; | ||
| 160 | return QScriptValue(); | ||
| 161 | } else { | ||
| 162 | qWarning() << "WebWindow views are deprecated. Use OverlayWebWindow instead"; | ||
| 163 | } | ||
| 185 | QMetaObject::invokeMethod(DependencyManager::get<WindowScriptingInterface>().data(), "doCreateWebWindow", Qt::BlockingQueuedConnection, | 164 | QMetaObject::invokeMethod(DependencyManager::get<WindowScriptingInterface>().data(), "doCreateWebWindow", Qt::BlockingQueuedConnection, |
| 186 | Q_RETURN_ARG(WebWindowClass*, retVal), | 165 | Q_RETURN_ARG(WebWindowClass*, retVal), |
| 187 | Q_ARG(const QString&, file), | 166 | Q_ARG(const QString&, file), |
| 188 | Q_ARG(QString, context->argument(1).toString()), | 167 | Q_ARG(QString, context->argument(1).toString()), |
| 189 | Q_ARG(int, context->argument(2).toInteger()), | 168 | Q_ARG(int, context->argument(2).toInteger()), |
| 190 | Q_ARG(int, context->argument(3).toInteger()), | 169 | Q_ARG(int, context->argument(3).toInteger())); |
| 191 | Q_ARG(bool, context->argument(4).toBool())); | ||
| 192 | 170 | ||
| 193 | connect(engine, &QScriptEngine::destroyed, retVal, &WebWindowClass::deleteLater); | 171 | connect(engine, &QScriptEngine::destroyed, retVal, &WebWindowClass::deleteLater); |
| 194 | 172 | ||