From 2e96585d9a36d95a5dd33859365b6047a133a051 Mon Sep 17 00:00:00 2001 From: matgic78 Date: Wed, 2 Dec 2009 18:01:30 +0100 Subject: Docked web inspector --- src/CMakeLists.txt | 2 ++ src/mainwindow.cpp | 47 +++++++++++++-------------- src/mainwindow.h | 14 +++++---- src/webinspectordock.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ src/webinspectordock.h | 59 ++++++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 32 deletions(-) create mode 100644 src/webinspectordock.cpp create mode 100644 src/webinspectordock.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23d5595e..78ca3106 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,8 @@ SET( rekonq_KDEINIT_SRCS #---------------------------------------- urlbar/urlbar.cpp urlbar/lineedit.cpp +#---------------------------------------- + webinspectordock.cpp ) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 628743ee..fc005014 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -42,6 +42,7 @@ #include "findbar.h" #include "sidepanel.h" #include "bookmarkspanel.h" +#include "webinspectordock.h" #include "urlbar.h" #include "tabbar.h" #include "newtabpage.h" @@ -99,7 +100,8 @@ MainWindow::MainWindow() , m_view(new MainView(this)) , m_findBar(new FindBar(this)) , m_sidePanel(0) - , m_bookmarksPanel(0) + , m_bookmarksPanel(0) + , m_webInspectorDock(0) , m_historyBackMenu(0) , m_mainBar( new KToolBar( QString("MainToolBar"), this, Qt::TopToolBarArea, true, false, false) ) , m_bmBar( new KToolBar( QString("BookmarkToolBar"), this, Qt::TopToolBarArea, true, false, false) ) @@ -136,7 +138,8 @@ MainWindow::MainWindow() // setting Side Panel setupSidePanel(); - setupBookmarksPanel(); + setupBookmarksPanel(); + setupWebInspector(); // setting up rekonq tools setupTools(); @@ -336,11 +339,6 @@ void MainWindow::setupActions() actionCollection()->addAction(QLatin1String("page_source"), a); connect(a, SIGNAL(triggered(bool)), this, SLOT(viewPageSource())); - a = new KAction(KIcon("tools-report-bug"), i18n("Web &Inspector"), this); - a->setCheckable(true); - actionCollection()->addAction(QLatin1String("web_inspector"), a); - connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleInspector(bool))); - a = new KAction(KIcon("view-media-artist"), i18n("Private &Browsing"), this); a->setCheckable(true); actionCollection()->addAction(QLatin1String("private_browsing"), a); @@ -490,6 +488,22 @@ void MainWindow::setupBookmarksPanel() } +void MainWindow::setupWebInspector() +{ + m_webInspectorDock = new WebInspectorDock(i18n("Web Inspector"), this); + connect(mainView(), SIGNAL(currentChanged(int)), m_webInspectorDock, SLOT(changeCurrentPage())); + + KAction *a = new KAction(KIcon("tools-report-bug"), i18n("Web &Inspector"), this); + a->setCheckable(true); + actionCollection()->addAction(QLatin1String("web_inspector"), a); + connect(a, SIGNAL(triggered(bool)), m_webInspectorDock, SLOT(toggle(bool))); + + addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorDock); + m_webInspectorDock->hide(); +} + + + void MainWindow::updateConfiguration() { // ============== General ================== @@ -843,25 +857,6 @@ void MainWindow::homePage() } -void MainWindow::toggleInspector(bool enable) -{ - QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, enable); - if (enable) - { - int result = KMessageBox::questionYesNo(this, - i18n("The web inspector will only work correctly for pages that were loaded after enabling.\n" \ - "Do you want to reload all pages?"), - i18n("Web Inspector") - ); - - if (result == KMessageBox::Yes) - { - m_view->reloadAllTabs(); - } - } -} - - MainView *MainWindow::mainView() const { return m_view; diff --git a/src/mainwindow.h b/src/mainwindow.h index d47b0d50..f141c5a2 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -48,6 +48,7 @@ class KPassivePopup; class FindBar; class SidePanel; class BookmarksPanel; +class WebInspectorDock; class WebView; class MainView; @@ -81,8 +82,10 @@ private: void setupSidePanel(); SidePanel *sidePanel(); - void setupBookmarksPanel(); - BookmarksPanel *bookmarksPanel(); + void setupBookmarksPanel(); + BookmarksPanel *bookmarksPanel(); + + void setupWebInspector(); public slots: void updateBrowser(); @@ -99,8 +102,7 @@ public slots: void notifyMessage(const QString &msg, Rekonq::Notify status = Rekonq::Info); void printRequested(QWebFrame *frame = 0); - - + signals: // switching tabs void ctrlTabPressed(); @@ -146,7 +148,6 @@ private slots: void viewFullScreen(bool enable); // Tools Menu slots - void toggleInspector(bool enable); void privateBrowsing(bool enable); // Settings Menu slot @@ -162,7 +163,8 @@ private: MainView *m_view; FindBar *m_findBar; SidePanel *m_sidePanel; - BookmarksPanel *m_bookmarksPanel; + BookmarksPanel *m_bookmarksPanel; + WebInspectorDock *m_webInspectorDock; KAction *m_stopReloadAction; KMenu *m_historyBackMenu; diff --git a/src/webinspectordock.cpp b/src/webinspectordock.cpp new file mode 100644 index 00000000..ada3af3f --- /dev/null +++ b/src/webinspectordock.cpp @@ -0,0 +1,82 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + +// Self Includes +#include "webinspectordock.h" + +// Local Includes +#include "webview.h" +#include "webpage.h" + +// Qt Includes +#include + +// KDE Includes +#include "KAction" +#include "KDebug" + + +WebInspectorDock::WebInspectorDock(QString title, QWidget *parent) + : QDockWidget(title, parent) +{ + setObjectName("webInspectorDock"); + QWebInspector *inspector = new QWebInspector(this); + setWidget(inspector); +} + +void WebInspectorDock::closeEvent(QCloseEvent *event) +{ + Q_UNUSED(event); + toggle(false); +} + +MainWindow* WebInspectorDock::mainWindow() +{ + return qobject_cast< MainWindow* >(parentWidget()); +} + + +void WebInspectorDock::toggle(bool enable) +{ + mainWindow()->actionByName("web_inspector")->setChecked(enable); + if (enable) + { + mainWindow()->currentTab()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); + findChild()->setPage(mainWindow()->currentTab()->page()); + show(); + } + else + { + hide(); + mainWindow()->currentTab()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false); + } +} + + +void WebInspectorDock::changeCurrentPage() +{ + bool enable = mainWindow()->currentTab()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled); + toggle(enable); +} diff --git a/src/webinspectordock.h b/src/webinspectordock.h new file mode 100644 index 00000000..b8ffa6c3 --- /dev/null +++ b/src/webinspectordock.h @@ -0,0 +1,59 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2009 by Lionel Chauvin +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +#ifndef WEBINSPECTORDOCK_H +#define WEBINSPECTORDOCK_H + + +// Local Includes +#include "mainwindow.h" + +// Qt Includes +#include + +/** + Docked web inspector + behaviour : hide/show by tab, not globally +*/ +class WebInspectorDock : public QDockWidget +{ + Q_OBJECT +public: + WebInspectorDock(QString title, QWidget *parent); + +public slots: + void toggle(bool enable); + void changeCurrentPage(); + +protected: + virtual void closeEvent(QCloseEvent *event); + + MainWindow *mainWindow(); + +}; + +#endif \ No newline at end of file -- cgit v1.2.1 From e466ef7f85267a843f7273351222389a6e498621 Mon Sep 17 00:00:00 2001 From: matgic78 Date: Wed, 2 Dec 2009 18:04:30 +0100 Subject: fix copyright --- src/webinspectordock.cpp | 2 +- src/webinspectordock.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/webinspectordock.cpp b/src/webinspectordock.cpp index ada3af3f..51fdbdaf 100644 --- a/src/webinspectordock.cpp +++ b/src/webinspectordock.cpp @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009 by Nils Weigel +* Copyright (C) 2009 by Matthieu Gicquel * * * This program is free software; you can redistribute it and/or diff --git a/src/webinspectordock.h b/src/webinspectordock.h index b8ffa6c3..c6697361 100644 --- a/src/webinspectordock.h +++ b/src/webinspectordock.h @@ -2,8 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 by Lionel Chauvin +* Copyright (C) 2009 by Matthieu Gicquel * * * This program is free software; you can redistribute it and/or -- cgit v1.2.1