From b87a805af7b066159ff4f10ff9c30fd7428ea706 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 24 Jan 2010 19:17:58 +0100 Subject: Fixing panels With this commit I fixed panel behaviour && saved some bytes in their definition. This will help hacking there (they are pretty the same now, I just have no time to let them inherit from a parent "rekonq panel" class) and will save some bytes in rekonq footprint :) --- src/CMakeLists.txt | 3 +- src/bookmarks/bookmarkspanel.cpp | 5 +-- src/bookmarks/bookmarkspanel.h | 3 -- src/history/historypanel.cpp | 82 +++++++++++++++++++++-------------- src/history/historypanel.h | 21 ++++----- src/history/sidepanel.cpp | 60 -------------------------- src/history/sidepanel.h | 58 ------------------------- src/mainwindow.cpp | 92 +++++++++++++++++----------------------- src/mainwindow.h | 19 +++------ src/rekonq.kcfg | 2 +- src/webinspectordock.cpp | 83 ------------------------------------ src/webinspectordock.h | 58 ------------------------- src/webinspectorpanel.cpp | 86 +++++++++++++++++++++++++++++++++++++ src/webinspectorpanel.h | 58 +++++++++++++++++++++++++ 14 files changed, 252 insertions(+), 378 deletions(-) delete mode 100644 src/history/sidepanel.cpp delete mode 100644 src/history/sidepanel.h delete mode 100644 src/webinspectordock.cpp delete mode 100644 src/webinspectordock.h create mode 100644 src/webinspectorpanel.cpp create mode 100644 src/webinspectorpanel.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c80aedc0..7a77c25c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,7 @@ SET( rekonq_KDEINIT_SRCS webtab.cpp clicktoflash.cpp networkaccessmanager.cpp - webinspectordock.cpp + webinspectorpanel.cpp walletbar.cpp protocolhandler.cpp #---------------------------------------- @@ -29,7 +29,6 @@ SET( rekonq_KDEINIT_SRCS history/historymanager.cpp history/historymodels.cpp history/historypanel.cpp - history/sidepanel.cpp #---------------------------------------- rekonqpage/newtabpage.cpp #---------------------------------------- diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp index 97097fbb..9164dbb6 100644 --- a/src/bookmarks/bookmarkspanel.cpp +++ b/src/bookmarks/bookmarkspanel.cpp @@ -57,7 +57,6 @@ BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::Window BookmarksPanel::~BookmarksPanel() { ReKonfig::setShowBookmarksPanel(!isHidden()); - delete ui; } @@ -73,7 +72,7 @@ void BookmarksPanel::setup() setObjectName("bookmarksPanel"); setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - ui = new QWidget(this); + QWidget *ui = new QWidget(this); // setup search bar QHBoxLayout *searchLayout = new QHBoxLayout; @@ -110,5 +109,5 @@ void BookmarksPanel::setup() treeView->setModel( proxy ); connect(search, SIGNAL(textChanged(QString)), proxy, SLOT(setFilterFixedString(QString))); - connect( treeView, SIGNAL( activated(QModelIndex) ), this, SLOT( bookmarkActivated(QModelIndex) ) ); + connect(treeView, SIGNAL( activated(QModelIndex) ), this, SLOT( bookmarkActivated(QModelIndex) ) ); } diff --git a/src/bookmarks/bookmarkspanel.h b/src/bookmarks/bookmarkspanel.h index b7c0b5ed..6c0e153f 100644 --- a/src/bookmarks/bookmarkspanel.h +++ b/src/bookmarks/bookmarkspanel.h @@ -38,7 +38,6 @@ class QModelIndex; class BookmarksPanel : public QDockWidget { Q_OBJECT - Q_DISABLE_COPY(BookmarksPanel) public: explicit BookmarksPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); @@ -52,8 +51,6 @@ private slots: private: void setup(); - - QWidget *ui; }; #endif // BOOKMARKSPANEL_H diff --git a/src/history/historypanel.cpp b/src/history/historypanel.cpp index 42497f9e..08dc3800 100644 --- a/src/history/historypanel.cpp +++ b/src/history/historypanel.cpp @@ -29,25 +29,52 @@ #include "historypanel.h" #include "historypanel.moc" +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "application.h" +#include "historymodels.h" + // Qt Includes #include #include #include +#include + // KDE Includes #include #include -HistoryPanel::HistoryPanel(QWidget *parent) - : QWidget(parent) - , m_historyTreeView(new QTreeView) - , m_treeProxyModel(new TreeProxyModel(this)) +HistoryPanel::HistoryPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) + : QDockWidget(title, parent, flags) +{ + setup(); + setShown(ReKonfig::showHistoryPanel()); +} + + +HistoryPanel::~HistoryPanel() +{ + // Save side panel's state + ReKonfig::setShowHistoryPanel(!isHidden()); +} + + +void HistoryPanel::setup() { - m_historyTreeView->setUniformRowHeights(true); - m_historyTreeView->setSelectionBehavior(QAbstractItemView::SelectRows); - m_historyTreeView->setTextElideMode(Qt::ElideMiddle); - m_historyTreeView->setAlternatingRowColors(true); + setObjectName("historyPanel"); + setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + QWidget *ui = new QWidget(this); + + QTreeView *historyTreeView = new QTreeView(this); + historyTreeView->setUniformRowHeights(true); + historyTreeView->setSelectionBehavior(QAbstractItemView::SelectRows); + historyTreeView->setTextElideMode(Qt::ElideMiddle); + historyTreeView->setAlternatingRowColors(true); // add search bar QHBoxLayout *hBoxLayout = new QHBoxLayout; @@ -60,42 +87,35 @@ HistoryPanel::HistoryPanel(QWidget *parent) QWidget *searchBar = new QWidget; searchBar->setLayout(hBoxLayout); - // setup view + // setup layout QVBoxLayout *vBoxLayout = new QVBoxLayout; vBoxLayout->setContentsMargins(0, 0, 0, 0); vBoxLayout->addWidget(searchBar); - vBoxLayout->addWidget(m_historyTreeView); - setLayout(vBoxLayout); + vBoxLayout->addWidget(historyTreeView); + + // add it to the UI + ui->setLayout(vBoxLayout); + setWidget(ui); //- HistoryManager *historyManager = Application::historyManager(); QAbstractItemModel *model = historyManager->historyTreeModel(); - m_treeProxyModel->setSourceModel(model); - m_historyTreeView->setModel(m_treeProxyModel); - m_historyTreeView->setExpanded(m_treeProxyModel->index(0, 0), true); - m_historyTreeView->header()->hideSection(1); + TreeProxyModel *treeProxyModel = new TreeProxyModel(this); + treeProxyModel->setSourceModel(model); + historyTreeView->setModel(treeProxyModel); + historyTreeView->setExpanded(treeProxyModel->index(0, 0), true); + historyTreeView->header()->hideSection(1); QFontMetrics fm(font()); int header = fm.width(QLatin1Char('m')) * 40; - m_historyTreeView->header()->resizeSection(0, header); - - connect(search, SIGNAL(textChanged(QString)), m_treeProxyModel, SLOT(setFilterFixedString(QString))); - connect(m_historyTreeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(open())); -} - + historyTreeView->header()->resizeSection(0, header); -HistoryPanel::~HistoryPanel() -{ - delete m_treeProxyModel; - delete m_historyTreeView; + connect(search, SIGNAL(textChanged(QString)), treeProxyModel, SLOT(setFilterFixedString(QString))); + connect(historyTreeView, SIGNAL(activated(const QModelIndex &)), this, SLOT(itemActivated(const QModelIndex &))); } -void HistoryPanel::open() +void HistoryPanel::itemActivated(const QModelIndex &item) { - QModelIndex index = m_historyTreeView->currentIndex(); - if (!index.parent().isValid()) - return; - emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); + emit openUrl( item.data(HistoryModel::UrlRole).toUrl() ); } - diff --git a/src/history/historypanel.h b/src/history/historypanel.h index 083b2741..e07e2190 100644 --- a/src/history/historypanel.h +++ b/src/history/historypanel.h @@ -29,36 +29,31 @@ #define HISTORYPANEL_H -// Local Includes -#include "application.h" -#include "historymodels.h" - // Qt Includes -#include -#include +#include // Forward Declarations class KUrl; +class QWidget; +class QModelIndex; -class HistoryPanel : public QWidget +class HistoryPanel : public QDockWidget { Q_OBJECT public: - explicit HistoryPanel(QWidget *parent = 0); - virtual ~HistoryPanel(); + explicit HistoryPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~HistoryPanel(); signals: void openUrl(const KUrl &); private slots: - void open(); + void itemActivated(const QModelIndex &); private: - QTreeView *m_historyTreeView; - TreeProxyModel *m_treeProxyModel; - + void setup(); }; #endif // HISTORYPANEL_H diff --git a/src/history/sidepanel.cpp b/src/history/sidepanel.cpp deleted file mode 100644 index 7c42301c..00000000 --- a/src/history/sidepanel.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* -* -* 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 "sidepanel.h" -#include "sidepanel.moc" - -// Auto Includes -#include "rekonq.h" - -// Local Includes -#include "historypanel.h" - - -SidePanel::SidePanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) - : QDockWidget(title, parent, flags) - , m_historyPanel(new HistoryPanel(this)) -{ - setObjectName("sidePanel"); - setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - - setShown(ReKonfig::showSideBar()); - - connect(m_historyPanel, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); - - setWidget(m_historyPanel); -} - - -SidePanel::~SidePanel() -{ - // Save side panel's state - ReKonfig::setShowSideBar(!isHidden()); - - delete m_historyPanel; -} diff --git a/src/history/sidepanel.h b/src/history/sidepanel.h deleted file mode 100644 index 6aca3587..00000000 --- a/src/history/sidepanel.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* -* -* 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 SIDEPANEL_H -#define SIDEPANEL_H - -// Local Includes -#include "application.h" - -// Qt Includes -#include - -// Forward Declarations -class KUrl; -class HistoryPanel; - - -class SidePanel : public QDockWidget -{ - Q_OBJECT - -public: - explicit SidePanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); - ~SidePanel(); - -signals: - void openUrl(const KUrl &); - -private: - HistoryPanel *m_historyPanel; - -}; - -#endif // SIDEPANEL_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9352ec36..659e5bf5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -40,9 +40,9 @@ #include "webtab.h" #include "mainview.h" #include "findbar.h" -#include "sidepanel.h" +#include "historypanel.h" #include "bookmarkspanel.h" -#include "webinspectordock.h" +#include "webinspectorpanel.h" #include "urlbar.h" #include "tabbar.h" #include "adblockmanager.h" @@ -98,9 +98,9 @@ MainWindow::MainWindow() : KMainWindow() , m_view( new MainView(this) ) , m_findBar( new FindBar(this) ) - , m_sidePanel(0) + , m_historyPanel(0) , m_bookmarksPanel(0) - , m_webInspectorDock(0) + , m_webInspectorPanel(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) ) @@ -134,10 +134,8 @@ MainWindow::MainWindow() // then, setup our actions setupActions(); - // setting Side Panel - setupSidePanel(); - setupBookmarksPanel(); - setupWebInspector(); + // setting Panels + setupPanels(); // setting up rekonq tools setupTools(); @@ -166,17 +164,6 @@ MainWindow::~MainWindow() } -SidePanel *MainWindow::sidePanel() -{ - return m_sidePanel; -} - -BookmarksPanel *MainWindow::bookmarksPanel() -{ - return m_bookmarksPanel; -} - - void MainWindow::setupToolbars() { // ============ Main ToolBar ================================ @@ -459,51 +446,50 @@ void MainWindow::setupTools() } -void MainWindow::setupSidePanel() +void MainWindow::setupPanels() { - // Setup history side panel - m_sidePanel = new SidePanel(i18n("History Panel"), this); - connect(m_sidePanel, SIGNAL(openUrl(const KUrl&)), Application::instance(), SLOT(loadUrl(const KUrl&))); - connect(m_sidePanel, SIGNAL(destroyed()), Application::instance(), SLOT(saveConfiguration())); + KAction* a; + + // STEP 1 + // Setup history panel + m_historyPanel = new HistoryPanel(i18n("History Panel"), this); + connect(m_historyPanel, SIGNAL(openUrl(const KUrl&)), Application::instance(), SLOT(loadUrl(const KUrl&))); + connect(m_historyPanel, SIGNAL(destroyed()), Application::instance(), SLOT(saveConfiguration())); - addDockWidget(Qt::LeftDockWidgetArea, m_sidePanel); + addDockWidget(Qt::LeftDockWidgetArea, m_historyPanel); - // setup side panel actions - KAction* a = (KAction *) m_sidePanel->toggleViewAction(); - a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_H)); + // setup history panel action + a = (KAction *) m_historyPanel->toggleViewAction(); + a->setShortcut( QKeySequence(Qt::CTRL + Qt::Key_H) ); a->setIcon(KIcon("view-history")); actionCollection()->addAction(QLatin1String("show_history_panel"), a); -} - -void MainWindow::setupBookmarksPanel() -{ + // STEP 2 + // Setup bookmarks panel m_bookmarksPanel = new BookmarksPanel(i18n("Bookmarks Panel"), this); connect(m_bookmarksPanel, SIGNAL(openUrl(const KUrl&)), Application::instance(), SLOT(loadUrl(const KUrl&))); connect(m_bookmarksPanel, SIGNAL(destroyed()), Application::instance(), SLOT(saveConfiguration())); addDockWidget(Qt::LeftDockWidgetArea, m_bookmarksPanel); - // setup side panel actions - KAction* a = (KAction *) m_bookmarksPanel->toggleViewAction(); - a->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B)); + // setup bookmarks panel action + a = (KAction *) m_bookmarksPanel->toggleViewAction(); + a->setShortcut( QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B) ); a->setIcon(KIcon("bookmarks-organize")); actionCollection()->addAction(QLatin1String("show_bookmarks_panel"), a); -} - -void MainWindow::setupWebInspector() -{ - m_webInspectorDock = new WebInspectorDock(i18n("Web Inspector"), this); - connect(mainView(), SIGNAL(currentChanged(int)), m_webInspectorDock, SLOT(changeCurrentPage())); + // STEP 3 + // Setup webinspector panel + m_webInspectorPanel = new WebInspectorPanel(i18n("Web Inspector"), this); + connect(mainView(), SIGNAL(currentChanged(int)), m_webInspectorPanel, SLOT(changeCurrentPage())); - KAction *a = new KAction(KIcon("tools-report-bug"), i18n("Web &Inspector"), this); + 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))); + connect(a, SIGNAL(triggered(bool)), m_webInspectorPanel, SLOT(toggle(bool))); - addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorDock); - m_webInspectorDock->hide(); + addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorPanel); + m_webInspectorPanel->hide(); } @@ -808,7 +794,7 @@ void MainWindow::setWidgetsVisible(bool makeVisible) { // state flags static bool bookmarksToolBarFlag; - static bool sidePanelFlag; + static bool historyPanelFlag; static bool bookmarksPanelFlag; if (!makeVisible) @@ -817,14 +803,14 @@ void MainWindow::setWidgetsVisible(bool makeVisible) if (!isFullScreen()) { bookmarksToolBarFlag = m_bmBar->isHidden(); - sidePanelFlag = sidePanel()->isHidden(); - bookmarksPanelFlag = bookmarksPanel()->isHidden(); + historyPanelFlag = m_historyPanel->isHidden(); + bookmarksPanelFlag = m_bookmarksPanel->isHidden(); } m_bmBar->hide(); m_view->setTabBarHidden(true); - sidePanel()->hide(); - bookmarksPanel()->hide(); + m_historyPanel->hide(); + m_bookmarksPanel->hide(); // hide main toolbar m_mainBar->hide(); @@ -838,10 +824,10 @@ void MainWindow::setWidgetsVisible(bool makeVisible) // restore state of windowed mode if (!bookmarksToolBarFlag) m_bmBar->show(); - if (!sidePanelFlag) - sidePanel()->show(); + if (!historyPanelFlag) + m_historyPanel->show(); if (!bookmarksPanelFlag) - bookmarksPanel()->show(); + m_bookmarksPanel->show(); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 49dc2a59..7083591d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -46,9 +46,9 @@ class KAction; class KPassivePopup; class FindBar; -class SidePanel; +class HistoryPanel; class BookmarksPanel; -class WebInspectorDock; +class WebInspectorPanel; class WebTab; class MainView; @@ -77,15 +77,8 @@ private: void setupActions(); void setupTools(); void setupToolbars(); - - void setupSidePanel(); - SidePanel *sidePanel(); - - void setupBookmarksPanel(); - BookmarksPanel *bookmarksPanel(); + void setupPanels(); - void setupWebInspector(); - public slots: void updateBrowser(); void homePage(); @@ -159,9 +152,10 @@ private slots: private: MainView *m_view; FindBar *m_findBar; - SidePanel *m_sidePanel; + + HistoryPanel *m_historyPanel; BookmarksPanel *m_bookmarksPanel; - WebInspectorDock *m_webInspectorDock; + WebInspectorPanel *m_webInspectorPanel; KAction *m_stopReloadAction; KMenu *m_historyBackMenu; @@ -178,4 +172,3 @@ private: }; #endif // MAINWINDOW_H - diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index f74fb144..a24508fc 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -35,7 +35,7 @@ http://www.kde.org/ - + false diff --git a/src/webinspectordock.cpp b/src/webinspectordock.cpp deleted file mode 100644 index 55ae11cf..00000000 --- a/src/webinspectordock.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Matthieu Gicquel -* -* -* 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" -#include "webinspectordock.moc" - -// Local Includes -#include "webtab.h" -#include "webview.h" -#include "webpage.h" - -// KDE Includes -#include "KAction" -#include "KDebug" - -// Qt Includes -#include - - -WebInspectorDock::WebInspectorDock(QString title, QWidget *parent) - : QDockWidget(title, parent) -{ - setObjectName("webInspectorDock"); - setWidget( new QWebInspector(this) ); -} - -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()->view()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); - findChild()->setPage(mainWindow()->currentTab()->page()); - show(); - } - else - { - hide(); - mainWindow()->currentTab()->view()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false); - } -} - - -void WebInspectorDock::changeCurrentPage() -{ - bool enable = mainWindow()->currentTab()->view()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled); - toggle(enable); -} diff --git a/src/webinspectordock.h b/src/webinspectordock.h deleted file mode 100644 index c6697361..00000000 --- a/src/webinspectordock.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Matthieu Gicquel -* -* -* 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 diff --git a/src/webinspectorpanel.cpp b/src/webinspectorpanel.cpp new file mode 100644 index 00000000..a038d280 --- /dev/null +++ b/src/webinspectorpanel.cpp @@ -0,0 +1,86 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Matthieu Gicquel +* +* +* 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 "webinspectorpanel.h" +#include "webinspectorpanel.moc" + +// Local Includes +#include "webtab.h" +#include "webview.h" +#include "webpage.h" + +// KDE Includes +#include "KAction" +#include "KDebug" + +// Qt Includes +#include + + +WebInspectorPanel::WebInspectorPanel(QString title, QWidget *parent) + : QDockWidget(title, parent) +{ + setObjectName("webInspectorDock"); + setWidget( new QWebInspector(this) ); +} + + +void WebInspectorPanel::closeEvent(QCloseEvent *event) +{ + Q_UNUSED(event); + toggle(false); +} + + +MainWindow* WebInspectorPanel::mainWindow() +{ + return qobject_cast< MainWindow* >(parentWidget()); +} + + +void WebInspectorPanel::toggle(bool enable) +{ + mainWindow()->actionByName("web_inspector")->setChecked(enable); + if (enable) + { + mainWindow()->currentTab()->view()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); + findChild()->setPage(mainWindow()->currentTab()->page()); + show(); + } + else + { + hide(); + mainWindow()->currentTab()->view()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false); + } +} + + +void WebInspectorPanel::changeCurrentPage() +{ + bool enable = mainWindow()->currentTab()->view()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled); + toggle(enable); +} diff --git a/src/webinspectorpanel.h b/src/webinspectorpanel.h new file mode 100644 index 00000000..8f65b48a --- /dev/null +++ b/src/webinspectorpanel.h @@ -0,0 +1,58 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Matthieu Gicquel +* +* +* 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 WEBINSPECTOR_PANEL_H +#define WEBINSPECTOR_PANEL_H + + +// Local Includes +#include "mainwindow.h" + +// Qt Includes +#include + +/** + Docked web inspector + behaviour : hide/show by tab, not globally +*/ +class WebInspectorPanel : public QDockWidget +{ + Q_OBJECT +public: + WebInspectorPanel(QString title, QWidget *parent); + +public slots: + void toggle(bool enable); + void changeCurrentPage(); + +protected: + virtual void closeEvent(QCloseEvent *event); + + MainWindow *mainWindow(); + +}; + +#endif -- cgit v1.2.1