1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the QtBrowser project.
8 ** $QT_BEGIN_LICENSE:GPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 2 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.GPLv2 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU General Public License version 2 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 3.0 as published by the Free Software
28 ** Foundation and appearing in the file LICENSE.GPL included in the
29 ** packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 3.0 requirements will be
31 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ****************************************************************************/
38 #include "browserwindow.h"
42 #include <QQmlContext>
49 void BrowserWindow::ensureProfileInstance()
51 if (m_lazyProfileInstance)
53 QQmlComponent *component = new QQmlComponent(engine(), this);
56 QByteArrayLiteral("import QtQuick 2.0\n"
57 "import QtWebEngine 1.1\n"
58 "WebEngineProfile {\n"
59 " storageName: \"YABProfile\"\n"
62 m_lazyProfileInstance = component->create(engine()->rootContext());
63 Q_ASSERT(m_lazyProfileInstance);
64 QQmlEngine::setObjectOwnership(m_lazyProfileInstance, QQmlEngine::JavaScriptOwnership);
67 QObject *BrowserWindow::defaultProfile()
69 ensureProfileInstance();
70 return m_lazyProfileInstance;
73 BrowserWindow::BrowserWindow(QWindow *)
74 : m_lazyProfileInstance(0)
76 setTitle("Yet Another Browser");
77 setFlags(Qt::Window | Qt::WindowTitleHint);
78 setResizeMode(QQuickView::SizeRootObjectToView);
81 engine()->rootContext()->setContextProperty("engine", new Engine(this));
82 setSource(QUrl("qrc:///qml/BrowserWindow.qml"));
85 BrowserWindow::~BrowserWindow()
89 void BrowserWindow::updateVisualMockTouchPoints(const QList<QTouchEvent::TouchPoint>& touchPoints)
91 if (touchPoints.isEmpty()) {
92 // Hide all touch indicator items.
93 foreach (QQuickItem* item, m_activeMockComponents.values())
94 item->setProperty("pressed", false);
99 foreach (const QTouchEvent::TouchPoint& touchPoint, touchPoints) {
100 QQuickItem* mockTouchPointItem = m_activeMockComponents.value(touchPoint.id());
102 if (!mockTouchPointItem) {
103 QQmlComponent touchMockPointComponent(engine(), QUrl("qrc:///qml/MockTouchPoint.qml"));
104 mockTouchPointItem = qobject_cast<QQuickItem*>(touchMockPointComponent.create());
105 Q_ASSERT(mockTouchPointItem);
106 m_activeMockComponents.insert(touchPoint.id(), mockTouchPointItem);
107 mockTouchPointItem->setProperty("pointId", QVariant(touchPoint.id()));
108 mockTouchPointItem->setParent(rootObject());
109 mockTouchPointItem->setParentItem(rootObject());
112 QRectF touchRect = touchPoint.rect();
113 mockTouchPointItem->setX(touchRect.center().x());
114 mockTouchPointItem->setY(touchRect.center().y());
115 mockTouchPointItem->setWidth(touchRect.width());
116 mockTouchPointItem->setHeight(touchRect.height());
117 mockTouchPointItem->setProperty("pressed", QVariant(touchPoint.state() != Qt::TouchPointReleased));