Commit 76419ba2 authored by Javier Delgado Fernandez's avatar Javier Delgado Fernandez Committed by Jonah Brüchert
Browse files

Add developer tools

parent 6c07c3d7
......@@ -3,9 +3,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick 2.3
import QtQuick.Controls 2.0
import QtQuick.Controls 2.15
import QtQml.Models 2.1
import QtWebEngine 1.6
import QtWebEngine 1.10
import org.kde.kirigami 2.7 as Kirigami
import org.kde.angelfish 1.0
......@@ -38,41 +38,70 @@ Repeater {
privateMode: privateTabsMode
}
delegate: WebView {
id: webView
anchors {
bottom: tabs.bottom
top: tabs.top
}
privateMode: tabs.privateTabsMode
userAgent.isMobile: model.isMobile
width: tabs.width
profile: tabs.profile
Component.onCompleted: {
url = model.pageurl
}
delegate: SplitView {
anchors.fill: parent
orientation: Qt.Vertical
property bool readyForSnapshot: false
property bool showView: index === tabs.currentIndex
visible: (showView || readyForSnapshot || loadingActive) && tabs.activeTabs
x: showView && tabs.activeTabs ? 0 : -width
z: showView && tabs.activeTabs ? 0 : -1
property bool isVisible: (showView || readyForSnapshot || loadingActive) && tabs.activeTabs
onShowViewChanged: {
if (showView) {
tabs.currentItem = webView
tabs.currentItem = pageWebView
}
}
x: showView && tabs.activeTabs ? 0 : -width
z: showView && tabs.activeTabs ? 0 : -1
visible: isVisible
Item {
SplitView.minimumHeight: 100
WebView {
id: pageWebView
anchors.fill: parent
visible: isVisible
privateMode: tabs.privateTabsMode
userAgent.isMobile: model.isMobile
width: tabs.width
profile: tabs.profile
Component.onCompleted: {
url = model.pageurl
}
onRequestedUrlChanged: tabsModel.setUrl(index, requestedUrl)
Connections {
target: pageWebView.userAgent
function onUserAgentChanged() {
tabsModel.setIsMobile(index, pageWebView.userAgent.isMobile);
}
}
}
}
onRequestedUrlChanged: tabsModel.setUrl(index, requestedUrl)
Connections {
target: webView.userAgent
function onUserAgentChanged() {
tabsModel.setIsMobile(index, webView.userAgent.isMobile);
Item {
SplitView.minimumHeight: 100
visible: model.isDeveloperToolsOpen
Loader {
id: developerToolsLoader
anchors.fill: parent
onLoaded: {
item.inspectedView = pageWebView;
}
Connections {
target: tabsModel
onDataChanged: {
if (model.isDeveloperToolsOpen) {
developerToolsLoader.setSource("WebDeveloperTools.qml");
}
}
}
}
}
}
......
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick 2.3
import QtWebEngine 1.10
WebEngineView {}
......@@ -7,5 +7,6 @@
<file alias="DownloadQuestion.qml">contents/ui/DownloadQuestion.qml</file>
<file alias="PermissionQuestion.qml">contents/ui/PermissionQuestion.qml</file>
<file alias="JavaScriptDialogSheet.qml">contents/ui/JavaScriptDialogSheet.qml</file>
<file alias="WebDeveloperTools.qml">contents/ui/WebDeveloperTools.qml</file>
</qresource>
</RCC>
......@@ -41,6 +41,7 @@ QHash<int, QByteArray> TabsModel::roleNames() const
return {
{RoleNames::UrlRole, QByteArrayLiteral("pageurl")},
{RoleNames::IsMobileRole, QByteArrayLiteral("isMobile")},
{RoleNames::IsDeveloperToolsOpen, QByteArrayLiteral("isDeveloperToolsOpen")},
};
}
......@@ -55,6 +56,8 @@ QVariant TabsModel::data(const QModelIndex &index, int role) const
return m_tabs.at(index.row()).url();
case RoleNames::IsMobileRole:
return m_tabs.at(index.row()).isMobile();
case RoleNames::IsDeveloperToolsOpen:
return m_tabs.at(index.row()).isDeveloperToolsOpen();
}
return {};
......@@ -333,6 +336,27 @@ void TabsModel::setIsMobile(int index, bool isMobile)
saveTabs();
}
void TabsModel::setIsDeveloperToolsOpen(int index, bool isDeveloperToolsOpen)
{
qDebug() << "Setting isDeveloperToolsOpen:" << index << isDeveloperToolsOpen << "tabs open" << m_tabs.count();
if (index < 0 && index >= m_tabs.count())
return; // index out of bounds
m_tabs[index].setIsDeveloperToolsOpen(isDeveloperToolsOpen);
const QModelIndex mindex = createIndex(index, index);
emit dataChanged(mindex, mindex, {RoleNames::IsDeveloperToolsOpen});
saveTabs();
}
bool TabsModel::isDeveloperToolsOpen(int index)
{
if (index < 0 && index >= m_tabs.count())
return false;
return m_tabs.at(index).isDeveloperToolsOpen();
}
void TabsModel::setUrl(int index, const QString &url)
{
qDebug() << "Setting URL:" << index << url << "tabs open" << m_tabs.count();
......@@ -366,11 +390,22 @@ void TabState::setIsMobile(bool isMobile)
m_isMobile = isMobile;
}
bool TabState::isDeveloperToolsOpen() const
{
return m_isDeveloperToolsOpen;
}
void TabState::setIsDeveloperToolsOpen(bool isDeveloperToolsOpen)
{
m_isDeveloperToolsOpen = isDeveloperToolsOpen;
}
TabState TabState::fromJson(const QJsonObject &obj)
{
TabState tab;
tab.setUrl(obj.value(QStringLiteral("url")).toString());
tab.setIsMobile(obj.value(QStringLiteral("isMobile")).toBool());
tab.setIsDeveloperToolsOpen(obj.value(QStringLiteral("isDeveloperToolsOpen")).toBool());
return tab;
}
......@@ -382,7 +417,11 @@ TabState::TabState(const QString &url, const bool isMobile)
bool TabState::operator==(const TabState &other) const
{
return (m_url == other.url() && m_isMobile == other.isMobile());
return (
m_url == other.url() &&
m_isMobile == other.isMobile() &&
m_isDeveloperToolsOpen == other.isDeveloperToolsOpen()
);
}
QJsonObject TabState::toJson() const
......@@ -390,5 +429,6 @@ QJsonObject TabState::toJson() const
return {
{QStringLiteral("url"), m_url},
{QStringLiteral("isMobile"), m_isMobile},
{QStringLiteral("isDeveloperToolsOpen"), m_isDeveloperToolsOpen},
};
}
......@@ -25,12 +25,16 @@ public:
bool isMobile() const;
void setIsMobile(bool isMobile);
bool isDeveloperToolsOpen() const;
void setIsDeveloperToolsOpen(bool isDeveloperToolsOpen);
QString url() const;
void setUrl(const QString &url);
private:
QString m_url;
bool m_isMobile = true;
bool m_isDeveloperToolsOpen = false;
};
class TabsModel : public QAbstractListModel
......@@ -41,7 +45,7 @@ class TabsModel : public QAbstractListModel
Q_PROPERTY(bool isMobileDefault READ isMobileDefault WRITE setIsMobileDefault NOTIFY isMobileDefaultChanged)
Q_PROPERTY(bool privateMode READ privateMode WRITE setPrivateMode NOTIFY privateModeChanged REQUIRED)
enum RoleNames { UrlRole = Qt::UserRole + 1, IsMobileRole };
enum RoleNames { UrlRole = Qt::UserRole + 1, IsMobileRole, IsDeveloperToolsOpen };
public:
explicit TabsModel(QObject *parent = nullptr);
......@@ -65,7 +69,9 @@ public:
Q_INVOKABLE void setUrl(int index, const QString &url);
Q_INVOKABLE void setIsMobile(int index, bool isMobile);
Q_INVOKABLE void setIsDeveloperToolsOpen(int index, bool isDeveloperToolsOpen);
Q_INVOKABLE bool isDeveloperToolsOpen(int index);
bool isMobileDefault() const;
void setIsMobileDefault(bool def);
......
......@@ -356,6 +356,15 @@ Kirigami.ApplicationWindow {
if (!navigation.visible) return;
rootPage.navigationAutoShow = !rootPage.navigationAutoShow;
}
},
Kirigami.Action {
icon.name: "dialog-scripts"
text: i18n("Show developer tools")
checkable: true
checked: tabs.tabsModel.isDeveloperToolsOpen(tabs.currentIndex);
onTriggered: {
tabs.tabsModel.setIsDeveloperToolsOpen(tabs.currentIndex, !tabs.tabsModel.isDeveloperToolsOpen(tabs.currentIndex))
}
}
]
......
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