1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

[WebInspector] WebInspector is now displayed inside WebTab

It no longer uses QDockWidget. Instead, it is plain QWidget with
close button in top right corner.
This commit is contained in:
nowrep 2014-03-31 17:46:59 +02:00
parent 7f3d8ee786
commit 2d9dfa9db7
8 changed files with 84 additions and 157 deletions

View File

@ -50,7 +50,6 @@
#include "browsinglibrary.h" #include "browsinglibrary.h"
#include "navigationbar.h" #include "navigationbar.h"
#include "pagescreen.h" #include "pagescreen.h"
#include "webinspector.h"
#include "bookmarksimport/bookmarksimportdialog.h" #include "bookmarksimport/bookmarksimportdialog.h"
#include "qztools.h" #include "qztools.h"
#include "actioncopy.h" #include "actioncopy.h"
@ -818,28 +817,11 @@ void BrowserWindow::toggleFullScreen()
} }
} }
void BrowserWindow::showWebInspector(bool toggle) void BrowserWindow::showWebInspector()
{ {
if (m_webInspectorDock) { if (weView() && weView()->webTab()) {
if (toggle) { weView()->webTab()->showWebInspector();
m_webInspectorDock.data()->toggleVisibility();
} }
else {
m_webInspectorDock.data()->show();
}
return;
}
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() void BrowserWindow::refreshHistory()
@ -1015,7 +997,7 @@ void BrowserWindow::searchOnPage()
SearchToolBar* toolBar = searchToolBar(); SearchToolBar* toolBar = searchToolBar();
if (!toolBar) { if (!toolBar) {
const int searchPos = 3; const int searchPos = 2;
toolBar = new SearchToolBar(weView(), this); toolBar = new SearchToolBar(weView(), this);
m_mainLayout->insertWidget(searchPos, toolBar); m_mainLayout->insertWidget(searchPos, toolBar);
@ -1413,7 +1395,7 @@ void BrowserWindow::closeEvent(QCloseEvent* event)
SearchToolBar* BrowserWindow::searchToolBar() const SearchToolBar* BrowserWindow::searchToolBar() const
{ {
SearchToolBar* toolBar = 0; SearchToolBar* toolBar = 0;
const int searchPos = 3; const int searchPos = 2;
if (m_mainLayout->count() == searchPos + 1) { if (m_mainLayout->count() == searchPos + 1) {
toolBar = qobject_cast<SearchToolBar*>(m_mainLayout->itemAt(searchPos)->widget()); toolBar = qobject_cast<SearchToolBar*>(m_mainLayout->itemAt(searchPos)->widget());
@ -1580,13 +1562,6 @@ void BrowserWindow::applyBlurToMainWindow(bool force)
bottomMargin += statusBar()->isVisible() ? statusBar()->height() : 0; 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); QtWin::extendFrameIntoClientArea(this, leftMargin, topMargin, rightMargin, bottomMargin);
} }
@ -1625,10 +1600,6 @@ bool BrowserWindow::nativeEvent(const QByteArray &eventType, void* _message, lon
search->installEventFilter(this); search->installEventFilter(this);
} }
if (m_webInspectorDock) {
m_webInspectorDock.data()->installEventFilter(this);
}
if (isVisible()) { if (isVisible()) {
hide(); hide();
show(); show();

View File

@ -52,7 +52,6 @@ class StatusBarMessage;
class NavigationBar; class NavigationBar;
class NavigationContainer; class NavigationContainer;
class ClickableLabel; class ClickableLabel;
class WebInspectorDockWidget;
class LocationBar; class LocationBar;
class QUPZILLA_EXPORT BrowserWindow : public QMainWindow class QUPZILLA_EXPORT BrowserWindow : public QMainWindow
@ -124,7 +123,7 @@ public slots:
void setWindowTitle(const QString &t); void setWindowTitle(const QString &t);
void showWebInspector(bool toggle = true); void showWebInspector();
void showHistoryManager(); void showHistoryManager();
void toggleShowMenubar(); void toggleShowMenubar();
@ -184,7 +183,6 @@ private:
QSplitter* m_mainSplitter; QSplitter* m_mainSplitter;
AdBlockIcon* m_adblockIcon; AdBlockIcon* m_adblockIcon;
QPointer<WebInspectorDockWidget> m_webInspectorDock;
TabWidget* m_tabWidget; TabWidget* m_tabWidget;
QPointer<SideBar> m_sideBar; QPointer<SideBar> m_sideBar;

View File

@ -539,7 +539,6 @@ void TabWidget::currentTabChanged(int index)
m_locationBars->setCurrentWidget(locBar); m_locationBars->setCurrentWidget(locBar);
} }
webTab->setCurrentTab();
m_window->currentTabChanged(); m_window->currentTabChanged();
emit changed(); emit changed();

View File

@ -16,74 +16,41 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */ * ============================================================ */
#include "webinspector.h" #include "webinspector.h"
#include "docktitlebarwidget.h" #include "toolbutton.h"
#include "webpage.h" #include "iconprovider.h"
#include "tabbedwebview.h"
#include "webtab.h"
#include "browserwindow.h"
WebInspectorDockWidget::WebInspectorDockWidget(BrowserWindow* window) #include <QTimer>
: QDockWidget(window)
, m_window(window) WebInspector::WebInspector(QWidget* parent)
: QWebInspector(parent)
, m_closeButton(0)
{ {
setWindowTitle(tr("Web Inspector")); setObjectName(QSL("web-inspector"));
setObjectName("WebInspector"); setMinimumHeight(80);
setFeatures(0);
setTitleBarWidget(new DockTitleBarWidget(tr("Web Inspector"), this));
show();
} }
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()) { // Prevent re-initializing QWebInspector after changing tab / virtual desktop
close(); Q_UNUSED(event);
}
else {
show();
}
} }
void WebInspectorDockWidget::close() void WebInspector::resizeEvent(QResizeEvent* event)
{ {
m_window->weView()->webTab()->setInspectorVisible(false); QWebInspector::resizeEvent(event);
m_window->weView()->setFocus();
hide(); QTimer::singleShot(0, this, SLOT(updateCloseButton()));
}
void WebInspectorDockWidget::show()
{
QWebPage* page = m_window->weView()->page();
QPointer<WebInspector> 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();
}
} }

View File

@ -19,46 +19,26 @@
#define WEBINSPECTORDOCKWIDGET_H #define WEBINSPECTORDOCKWIDGET_H
#include <QWebInspector> #include <QWebInspector>
#include <QDockWidget>
#include <QPointer>
#include <QHash>
#include "qzcommon.h" #include "qzcommon.h"
class ToolButton;
class QUPZILLA_EXPORT WebInspector : public QWebInspector 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 Q_OBJECT
public: public:
explicit WebInspectorDockWidget(BrowserWindow* window); explicit WebInspector(QWidget* parent = 0);
~WebInspectorDockWidget();
void toggleVisibility(); private slots:
void updateCloseButton();
signals:
public slots:
void tabChanged(int index);
void close();
void show();
private: private:
BrowserWindow* m_window; void hideEvent(QHideEvent* event);
QHash<QWebPage*, QPointer<WebInspector> > m_inspectors; void resizeEvent(QResizeEvent* event);
QPointer<WebInspector> m_currentInspector; ToolButton* m_closeButton;
}; };
#endif // WEBINSPECTORDOCKWIDGET_H #endif // WEBINSPECTORDOCKWIDGET_H

View File

@ -71,7 +71,7 @@ void TabbedWebView::setWebPage(WebPage* page)
void TabbedWebView::inspectElement() void TabbedWebView::inspectElement()
{ {
m_window->showWebInspector(false); m_window->showWebInspector();
triggerPageAction(QWebPage::InspectElement); triggerPageAction(QWebPage::InspectElement);
} }

View File

@ -18,6 +18,7 @@
#include "webtab.h" #include "webtab.h"
#include "browserwindow.h" #include "browserwindow.h"
#include "tabbedwebview.h" #include "tabbedwebview.h"
#include "webinspector.h"
#include "webpage.h" #include "webpage.h"
#include "tabbar.h" #include "tabbar.h"
#include "tabicon.h" #include "tabicon.h"
@ -32,6 +33,7 @@
#include <QWebFrame> #include <QWebFrame>
#include <QLabel> #include <QLabel>
#include <QTimer> #include <QTimer>
#include <QSplitter>
static const int savedTabVersion = 1; static const int savedTabVersion = 1;
@ -86,20 +88,18 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
WebTab::WebTab(BrowserWindow* window) WebTab::WebTab(BrowserWindow* window)
: QWidget() : QWidget()
, m_window(window) , m_window(window)
, m_inspector(0)
, m_tabBar(window->tabWidget()->getTabBar()) , m_tabBar(window->tabWidget()->getTabBar())
, m_isPinned(false) , m_isPinned(false)
, m_inspectorVisible(false)
{ {
setObjectName("webtab"); setObjectName(QSL("webtab"));
// This fixes background of pages with dark themes // This fixes background of pages with dark themes
setStyleSheet("#webtab {background-color:white;}"); setStyleSheet("#webtab {background-color:white;}");
m_webView = new TabbedWebView(m_window, this); m_webView = new TabbedWebView(m_window, this);
m_webView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); m_webView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
m_webView->setWebPage(new WebPage(m_webView));
WebPage* page = new WebPage(m_webView);
m_webView->setWebPage(page);
m_locationBar = new LocationBar(m_window); m_locationBar = new LocationBar(m_window);
m_locationBar->setWebView(m_webView); m_locationBar->setWebView(m_webView);
@ -107,10 +107,14 @@ WebTab::WebTab(BrowserWindow* window)
m_tabIcon = new TabIcon(this); m_tabIcon = new TabIcon(this);
m_tabIcon->setWebTab(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 = new QVBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 0); m_layout->setContentsMargins(0, 0, 0, 0);
m_layout->setSpacing(0); m_layout->setSpacing(0);
m_layout->addWidget(m_webView); m_layout->addWidget(m_splitter);
setLayout(m_layout); setLayout(m_layout);
connect(m_webView, SIGNAL(showNotification(QWidget*)), this, SLOT(showNotification(QWidget*))); connect(m_webView, SIGNAL(showNotification(QWidget*)), this, SLOT(showNotification(QWidget*)));
@ -121,17 +125,15 @@ TabbedWebView* WebTab::webView() const
return m_webView; return m_webView;
} }
void WebTab::setCurrentTab() void WebTab::showWebInspector()
{ {
if (!isRestored()) { if (!m_inspector) {
// When session is being restored, restore the tab immediately m_inspector = new WebInspector(this);
if (mApp->isRestoring()) { m_inspector->setPage(m_webView->page());
slotRestore(); m_splitter->addWidget(m_inspector);
}
else {
QTimer::singleShot(0, this, SLOT(slotRestore()));
}
} }
m_inspector->show();
} }
QUrl WebTab::url() const QUrl WebTab::url() const
@ -244,16 +246,6 @@ TabIcon* WebTab::tabIcon() const
return m_tabIcon; return m_tabIcon;
} }
bool WebTab::inspectorVisible() const
{
return m_inspectorVisible;
}
void WebTab::setInspectorVisible(bool v)
{
m_inspectorVisible = v;
}
bool WebTab::isRestored() const bool WebTab::isRestored() const
{ {
return m_savedTab.isEmpty(); return m_savedTab.isEmpty();
@ -358,6 +350,22 @@ void WebTab::slotRestore()
m_tabBar->restoreTabTextColor(tabIndex()); 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 bool WebTab::isCurrentTab() const
{ {
return tabIndex() == m_tabBar->currentIndex(); return tabIndex() == m_tabBar->currentIndex();

View File

@ -26,10 +26,12 @@
class QVBoxLayout; class QVBoxLayout;
class QWebHistory; class QWebHistory;
class QSplitter;
class BrowserWindow; class BrowserWindow;
class LocationBar;
class TabbedWebView; class TabbedWebView;
class WebInspector;
class LocationBar;
class TabIcon; class TabIcon;
class TabBar; class TabBar;
@ -82,10 +84,8 @@ public:
void pinTab(int index); void pinTab(int index);
bool isCurrentTab() const; bool isCurrentTab() const;
void setCurrentTab();
bool inspectorVisible() const; void showWebInspector();
void setInspectorVisible(bool v);
bool isRestored() const; bool isRestored() const;
void restoreTab(const SavedTab &tab); void restoreTab(const SavedTab &tab);
@ -99,16 +99,20 @@ private slots:
void slotRestore(); void slotRestore();
private: private:
void showEvent(QShowEvent* event);
BrowserWindow* m_window; BrowserWindow* m_window;
QVBoxLayout* m_layout;
QSplitter* m_splitter;
TabbedWebView* m_webView; TabbedWebView* m_webView;
WebInspector* m_inspector;
LocationBar* m_locationBar; LocationBar* m_locationBar;
TabIcon* m_tabIcon; TabIcon* m_tabIcon;
TabBar* m_tabBar; TabBar* m_tabBar;
QVBoxLayout* m_layout;
SavedTab m_savedTab; SavedTab m_savedTab;
bool m_isPinned; bool m_isPinned;
bool m_inspectorVisible;
}; };
#endif // WEBTAB_H #endif // WEBTAB_H