Commit adf29180 authored by Stefano Crocco's avatar Stefano Crocco Committed by David Faure
Browse files

Add functionality to display developer tools for the current page

parent 578f4414
......@@ -232,7 +232,6 @@ KonqMainWindow::KonqMainWindow(const QUrl &initialURL)
#endif
m_pViewManager = new KonqViewManager(this);
m_viewModeMenu = nullptr;
m_openWithMenu = nullptr;
m_paCopyFiles = nullptr;
......@@ -2080,6 +2079,8 @@ void KonqMainWindow::slotPartActivated(KParts::Part *part)
}
}
m_paShowDeveloperTools->setEnabled(m_currentView && m_currentView->isWebEngineView());
createGUI(part);
// View-dependent GUI
......@@ -3906,6 +3907,12 @@ void KonqMainWindow::initActions()
m_paLockView->setStatusTip(i18n("A locked view cannot change folders. Use in combination with 'link view' to explore many files from one folder"));
m_paLinkView->setStatusTip(i18n("Sets the view as 'linked'. A linked view follows folder changes made in other linked views."));
m_paShowDeveloperTools = actionCollection()->addAction("inspect_page", this, &KonqMainWindow::inspectCurrentPage);
actionCollection()->setDefaultShortcut(m_paShowDeveloperTools, QKeySequence("Ctrl+Shift+I"));
m_paShowDeveloperTools->setText(i18n("&Inspect Current Page"));
m_paShowDeveloperTools->setWhatsThis(i18n("<html>Shows the developer tools for the current page<br/><br/>The current view is split in two and the developer tools are displayed in the second half"));
m_paShowDeveloperTools->setStatusTip(i18n("Shows the developer tools for the current page"));
}
void KonqExtendedBookmarkOwner::openBookmark(const KBookmark &bm, Qt::MouseButtons mb, Qt::KeyboardModifiers km)
......@@ -5722,3 +5729,20 @@ void KonqMainWindow::FullScreenData::switchToState(KonqMainWindow::FullScreenSta
currentState = newState;
}
}
void KonqMainWindow::inspectCurrentPage()
{
if (!m_currentView || !m_currentView->isWebEngineView()) {
return;
}
KParts::ReadOnlyPart *partToInspect = m_currentView->part();
KonqView *devToolsView = m_pViewManager->splitView(m_currentView, Qt::Vertical);
if (devToolsView == nullptr) {
return;
}
KonqOpenURLRequest req;
req.forceAutoEmbed = true;
openView("text/html", QUrl(), devToolsView, req);
QMetaObject::invokeMethod(devToolsView->part(), "setInspectedPart", Qt::DirectConnection, Q_ARG(KParts::ReadOnlyPart*, partToInspect));
}
......@@ -558,6 +558,8 @@ private Q_SLOTS:
* to Konqueror's own and emits the spellCheckConfigurationChanged signal
*/
void updateSpellCheckConfiguration();
void inspectCurrentPage();
private:
void updateWindowIcon();
......@@ -673,6 +675,8 @@ private: // members
KToggleFullScreenAction *m_ptaFullScreen;
QAction *m_paShowDeveloperTools;
bool m_fullyConstructed: 1;
bool m_bLocationBarConnected: 1;
bool m_bURLEnterLock: 1;
......
<?xml version="1.0"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="Konqueror" version="71">
<gui name="Konqueror" version="72">
<MenuBar>
<Menu name="file" noMerge="1"><text>&amp;File</text>
<Action name="new_window"/>
......@@ -51,6 +51,11 @@
<Action name="closeditems"/>
</Menu>
<Action name="bookmarks"/>
<Menu name="tools"><text>&amp;Tools</text>
<Merge name="tools" />
<Action name="inspect_page"/>
<Separator />
</Menu>
<Menu name="settings" noMerge="1"><text>&amp;Settings</text>
<Merge name="StandardToolBarMenuHandler" />
<Action name="options_show_menubar"/>
......
......@@ -140,6 +140,11 @@ KonqView::~KonqView()
//qCDebug(KONQUEROR_LOG) << this << "done";
}
bool KonqView::isWebEngineView() const
{
return m_service->desktopEntryName() == QLatin1String("webenginepart");
}
void KonqView::openUrl(const QUrl &url, const QString &locationBarURL,
const QString &nameFilter, bool tempFile)
{
......
......@@ -103,6 +103,8 @@ public:
~KonqView() override;
bool isWebEngineView() const;
/**
* Displays another URL, but without changing the view mode (caller has to
* ensure that the call makes sense)
......
......@@ -93,6 +93,16 @@ WebEnginePage::WebEnginePage(WebEnginePart *part, QWidget *parent)
connect(this, &QWebEnginePage::authenticationRequired,
this, &WebEnginePage::slotAuthenticationRequired);
connect(this, &QWebEnginePage::fullScreenRequested, this, &WebEnginePage::changeFullScreenMode);
//If this part is displaying the developer tools for another part, inform the other page it's not displaying the developer tools anymore.
//I'm not sure this is needed, but I think it's better to do it, just to be on the safe side
auto unsetInspectedPageIfNeeded = [this](bool ok) {
if (ok && inspectedPage() && url().scheme() != QLatin1String("devtools")) {
setInspectedPage(nullptr);
}
};
connect(this, &QWebEnginePage::loadFinished, this, unsetInspectedPageIfNeeded);
if(!this->profile()->httpUserAgent().contains(QLatin1String("Konqueror")))
{
this->profile()->setHttpUserAgent(this->profile()->httpUserAgent() + " Konqueror (WebEnginePart)");
......
......@@ -1132,3 +1132,13 @@ void WebEnginePart::updateWalletData(std::initializer_list<bool> data)
updateWalletActions();
updateWalletStatusBarIcon();
}
void WebEnginePart::setInspectedPart(KParts::ReadOnlyPart* part)
{
WebEnginePart *wpart = qobject_cast<WebEnginePart*>(part);
if (!wpart) {
return;
}
page()->setInspectedPage(wpart->page());
setUrl(page()->url());
}
......@@ -114,6 +114,7 @@ public:
public Q_SLOTS:
void exitFullScreen();
void setInspectedPart(KParts::ReadOnlyPart *part);
protected:
/**
......
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