From 2d9dfa9db7d1aa5d356c87e787cee2fa66b749a4 Mon Sep 17 00:00:00 2001 From: nowrep Date: Mon, 31 Mar 2014 17:46:59 +0200 Subject: [PATCH] [WebInspector] WebInspector is now displayed inside WebTab It no longer uses QDockWidget. Instead, it is plain QWidget with close button in top right corner. --- src/lib/app/browserwindow.cpp | 39 ++------------- src/lib/app/browserwindow.h | 4 +- src/lib/tabwidget/tabwidget.cpp | 1 - src/lib/webkit/webinspector.cpp | 83 ++++++++++---------------------- src/lib/webkit/webinspector.h | 38 ++++----------- src/lib/webtab/tabbedwebview.cpp | 2 +- src/lib/webtab/webtab.cpp | 58 ++++++++++++---------- src/lib/webtab/webtab.h | 16 +++--- 8 files changed, 84 insertions(+), 157 deletions(-) diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index a4ae17be1..dc775da2c 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -50,7 +50,6 @@ #include "browsinglibrary.h" #include "navigationbar.h" #include "pagescreen.h" -#include "webinspector.h" #include "bookmarksimport/bookmarksimportdialog.h" #include "qztools.h" #include "actioncopy.h" @@ -818,28 +817,11 @@ void BrowserWindow::toggleFullScreen() } } -void BrowserWindow::showWebInspector(bool toggle) +void BrowserWindow::showWebInspector() { - if (m_webInspectorDock) { - if (toggle) { - m_webInspectorDock.data()->toggleVisibility(); - } - else { - m_webInspectorDock.data()->show(); - } - return; + if (weView() && weView()->webTab()) { + weView()->webTab()->showWebInspector(); } - - m_webInspectorDock = new WebInspectorDockWidget(this); - connect(m_tabWidget, SIGNAL(currentChanged(int)), m_webInspectorDock.data(), SLOT(tabChanged(int))); - addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorDock.data()); - -#ifdef Q_OS_WIN - if (QtWin::isCompositionEnabled()) { - applyBlurToMainWindow(); - m_webInspectorDock.data()->installEventFilter(this); - } -#endif } void BrowserWindow::refreshHistory() @@ -1015,7 +997,7 @@ void BrowserWindow::searchOnPage() SearchToolBar* toolBar = searchToolBar(); if (!toolBar) { - const int searchPos = 3; + const int searchPos = 2; toolBar = new SearchToolBar(weView(), this); m_mainLayout->insertWidget(searchPos, toolBar); @@ -1413,7 +1395,7 @@ void BrowserWindow::closeEvent(QCloseEvent* event) SearchToolBar* BrowserWindow::searchToolBar() const { SearchToolBar* toolBar = 0; - const int searchPos = 3; + const int searchPos = 2; if (m_mainLayout->count() == searchPos + 1) { toolBar = qobject_cast(m_mainLayout->itemAt(searchPos)->widget()); @@ -1580,13 +1562,6 @@ void BrowserWindow::applyBlurToMainWindow(bool force) bottomMargin += statusBar()->isVisible() ? statusBar()->height() : 0; - if (m_webInspectorDock) { - bottomMargin += m_webInspectorDock.data()->isVisible() - ? m_webInspectorDock.data()->height() - + m_webInspectorDock.data()->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent) - : 0; - } - QtWin::extendFrameIntoClientArea(this, leftMargin, topMargin, rightMargin, bottomMargin); } @@ -1625,10 +1600,6 @@ bool BrowserWindow::nativeEvent(const QByteArray &eventType, void* _message, lon search->installEventFilter(this); } - if (m_webInspectorDock) { - m_webInspectorDock.data()->installEventFilter(this); - } - if (isVisible()) { hide(); show(); diff --git a/src/lib/app/browserwindow.h b/src/lib/app/browserwindow.h index 097741a53..3ca485e15 100644 --- a/src/lib/app/browserwindow.h +++ b/src/lib/app/browserwindow.h @@ -52,7 +52,6 @@ class StatusBarMessage; class NavigationBar; class NavigationContainer; class ClickableLabel; -class WebInspectorDockWidget; class LocationBar; class QUPZILLA_EXPORT BrowserWindow : public QMainWindow @@ -124,7 +123,7 @@ public slots: void setWindowTitle(const QString &t); - void showWebInspector(bool toggle = true); + void showWebInspector(); void showHistoryManager(); void toggleShowMenubar(); @@ -184,7 +183,6 @@ private: QSplitter* m_mainSplitter; AdBlockIcon* m_adblockIcon; - QPointer m_webInspectorDock; TabWidget* m_tabWidget; QPointer m_sideBar; diff --git a/src/lib/tabwidget/tabwidget.cpp b/src/lib/tabwidget/tabwidget.cpp index ae59dc3eb..0b17ba77c 100644 --- a/src/lib/tabwidget/tabwidget.cpp +++ b/src/lib/tabwidget/tabwidget.cpp @@ -539,7 +539,6 @@ void TabWidget::currentTabChanged(int index) m_locationBars->setCurrentWidget(locBar); } - webTab->setCurrentTab(); m_window->currentTabChanged(); emit changed(); diff --git a/src/lib/webkit/webinspector.cpp b/src/lib/webkit/webinspector.cpp index 6ded619d4..d9d0e2bf7 100644 --- a/src/lib/webkit/webinspector.cpp +++ b/src/lib/webkit/webinspector.cpp @@ -16,74 +16,41 @@ * along with this program. If not, see . * ============================================================ */ #include "webinspector.h" -#include "docktitlebarwidget.h" -#include "webpage.h" -#include "tabbedwebview.h" -#include "webtab.h" -#include "browserwindow.h" +#include "toolbutton.h" +#include "iconprovider.h" -WebInspectorDockWidget::WebInspectorDockWidget(BrowserWindow* window) - : QDockWidget(window) - , m_window(window) +#include + +WebInspector::WebInspector(QWidget* parent) + : QWebInspector(parent) + , m_closeButton(0) { - setWindowTitle(tr("Web Inspector")); - setObjectName("WebInspector"); - setFeatures(0); - setTitleBarWidget(new DockTitleBarWidget(tr("Web Inspector"), this)); - - show(); + setObjectName(QSL("web-inspector")); + setMinimumHeight(80); } -WebInspectorDockWidget::~WebInspectorDockWidget() +void WebInspector::updateCloseButton() { + if (!m_closeButton) { + m_closeButton = new ToolButton(this); + m_closeButton->setAutoRaise(true); + m_closeButton->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton)); + connect(m_closeButton, SIGNAL(clicked()), this, SLOT(hide())); + } + + m_closeButton->show(); + m_closeButton->move(width() - m_closeButton->width(), 0); } -void WebInspectorDockWidget::toggleVisibility() +void WebInspector::hideEvent(QHideEvent* event) { - if (isVisible()) { - close(); - } - else { - show(); - } + // Prevent re-initializing QWebInspector after changing tab / virtual desktop + Q_UNUSED(event); } -void WebInspectorDockWidget::close() +void WebInspector::resizeEvent(QResizeEvent* event) { - m_window->weView()->webTab()->setInspectorVisible(false); - m_window->weView()->setFocus(); + QWebInspector::resizeEvent(event); - hide(); -} - -void WebInspectorDockWidget::show() -{ - QWebPage* page = m_window->weView()->page(); - QPointer inspector = m_inspectors[page]; - - if (!inspector) { - inspector = new WebInspector(this); - inspector.data()->setPage(m_window->weView()->page()); - - m_inspectors[page] = inspector; - } - - if (m_currentInspector != inspector) { - setWidget(inspector.data()); - m_currentInspector = inspector; - } - - m_window->weView()->webTab()->setInspectorVisible(true); - - QDockWidget::show(); -} - -void WebInspectorDockWidget::tabChanged(int index) -{ - if (index >= 0 && m_window->weView()->webTab()->inspectorVisible()) { - show(); - } - else { - close(); - } + QTimer::singleShot(0, this, SLOT(updateCloseButton())); } diff --git a/src/lib/webkit/webinspector.h b/src/lib/webkit/webinspector.h index 0cb086ddd..8a4f6e1e2 100644 --- a/src/lib/webkit/webinspector.h +++ b/src/lib/webkit/webinspector.h @@ -19,46 +19,26 @@ #define WEBINSPECTORDOCKWIDGET_H #include -#include -#include -#include #include "qzcommon.h" +class ToolButton; + class QUPZILLA_EXPORT WebInspector : public QWebInspector -{ -public: - explicit WebInspector(QWidget* parent) : QWebInspector(parent) { } - -private: - void hideEvent(QHideEvent*) { - // Prevent re-initializing QWebInspector after changing tab / virtual desktop - } -}; - -class BrowserWindow; -class QUPZILLA_EXPORT WebInspectorDockWidget : public QDockWidget { Q_OBJECT + public: - explicit WebInspectorDockWidget(BrowserWindow* window); - ~WebInspectorDockWidget(); + explicit WebInspector(QWidget* parent = 0); - void toggleVisibility(); - -signals: - -public slots: - void tabChanged(int index); - - void close(); - void show(); +private slots: + void updateCloseButton(); private: - BrowserWindow* m_window; - QHash > m_inspectors; + void hideEvent(QHideEvent* event); + void resizeEvent(QResizeEvent* event); - QPointer m_currentInspector; + ToolButton* m_closeButton; }; #endif // WEBINSPECTORDOCKWIDGET_H diff --git a/src/lib/webtab/tabbedwebview.cpp b/src/lib/webtab/tabbedwebview.cpp index b8e2a1342..fd797efcf 100644 --- a/src/lib/webtab/tabbedwebview.cpp +++ b/src/lib/webtab/tabbedwebview.cpp @@ -71,7 +71,7 @@ void TabbedWebView::setWebPage(WebPage* page) void TabbedWebView::inspectElement() { - m_window->showWebInspector(false); + m_window->showWebInspector(); triggerPageAction(QWebPage::InspectElement); } diff --git a/src/lib/webtab/webtab.cpp b/src/lib/webtab/webtab.cpp index a54a2c47d..b142f1b55 100644 --- a/src/lib/webtab/webtab.cpp +++ b/src/lib/webtab/webtab.cpp @@ -18,6 +18,7 @@ #include "webtab.h" #include "browserwindow.h" #include "tabbedwebview.h" +#include "webinspector.h" #include "webpage.h" #include "tabbar.h" #include "tabicon.h" @@ -32,6 +33,7 @@ #include #include #include +#include static const int savedTabVersion = 1; @@ -86,20 +88,18 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab) WebTab::WebTab(BrowserWindow* window) : QWidget() , m_window(window) + , m_inspector(0) , m_tabBar(window->tabWidget()->getTabBar()) , m_isPinned(false) - , m_inspectorVisible(false) { - setObjectName("webtab"); + setObjectName(QSL("webtab")); // This fixes background of pages with dark themes setStyleSheet("#webtab {background-color:white;}"); m_webView = new TabbedWebView(m_window, this); m_webView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - - WebPage* page = new WebPage(m_webView); - m_webView->setWebPage(page); + m_webView->setWebPage(new WebPage(m_webView)); m_locationBar = new LocationBar(m_window); m_locationBar->setWebView(m_webView); @@ -107,10 +107,14 @@ WebTab::WebTab(BrowserWindow* window) m_tabIcon = new TabIcon(this); m_tabIcon->setWebTab(this); + m_splitter = new QSplitter(Qt::Vertical, this); + m_splitter->setChildrenCollapsible(false); + m_splitter->addWidget(m_webView); + m_layout = new QVBoxLayout(this); m_layout->setContentsMargins(0, 0, 0, 0); m_layout->setSpacing(0); - m_layout->addWidget(m_webView); + m_layout->addWidget(m_splitter); setLayout(m_layout); connect(m_webView, SIGNAL(showNotification(QWidget*)), this, SLOT(showNotification(QWidget*))); @@ -121,17 +125,15 @@ TabbedWebView* WebTab::webView() const return m_webView; } -void WebTab::setCurrentTab() +void WebTab::showWebInspector() { - if (!isRestored()) { - // When session is being restored, restore the tab immediately - if (mApp->isRestoring()) { - slotRestore(); - } - else { - QTimer::singleShot(0, this, SLOT(slotRestore())); - } + if (!m_inspector) { + m_inspector = new WebInspector(this); + m_inspector->setPage(m_webView->page()); + m_splitter->addWidget(m_inspector); } + + m_inspector->show(); } QUrl WebTab::url() const @@ -244,16 +246,6 @@ TabIcon* WebTab::tabIcon() const return m_tabIcon; } -bool WebTab::inspectorVisible() const -{ - return m_inspectorVisible; -} - -void WebTab::setInspectorVisible(bool v) -{ - m_inspectorVisible = v; -} - bool WebTab::isRestored() const { return m_savedTab.isEmpty(); @@ -358,6 +350,22 @@ void WebTab::slotRestore() m_tabBar->restoreTabTextColor(tabIndex()); } +void WebTab::showEvent(QShowEvent* event) +{ + QWidget::showEvent(event); + + if (!isRestored()) { + // When session is being restored, restore the tab immediately + if (mApp->isRestoring()) { + slotRestore(); + } + else { + QTimer::singleShot(0, this, SLOT(slotRestore())); + } + } + +} + bool WebTab::isCurrentTab() const { return tabIndex() == m_tabBar->currentIndex(); diff --git a/src/lib/webtab/webtab.h b/src/lib/webtab/webtab.h index 9161c0093..ca20f5e46 100644 --- a/src/lib/webtab/webtab.h +++ b/src/lib/webtab/webtab.h @@ -26,10 +26,12 @@ class QVBoxLayout; class QWebHistory; +class QSplitter; class BrowserWindow; -class LocationBar; class TabbedWebView; +class WebInspector; +class LocationBar; class TabIcon; class TabBar; @@ -82,10 +84,8 @@ public: void pinTab(int index); bool isCurrentTab() const; - void setCurrentTab(); - bool inspectorVisible() const; - void setInspectorVisible(bool v); + void showWebInspector(); bool isRestored() const; void restoreTab(const SavedTab &tab); @@ -99,16 +99,20 @@ private slots: void slotRestore(); private: + void showEvent(QShowEvent* event); + BrowserWindow* m_window; + QVBoxLayout* m_layout; + QSplitter* m_splitter; + TabbedWebView* m_webView; + WebInspector* m_inspector; LocationBar* m_locationBar; TabIcon* m_tabIcon; TabBar* m_tabBar; - QVBoxLayout* m_layout; SavedTab m_savedTab; bool m_isPinned; - bool m_inspectorVisible; }; #endif // WEBTAB_H