1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +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 "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();
if (weView() && weView()->webTab()) {
weView()->webTab()->showWebInspector();
}
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()
@ -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<SearchToolBar*>(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();

View File

@ -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<WebInspectorDockWidget> m_webInspectorDock;
TabWidget* m_tabWidget;
QPointer<SideBar> m_sideBar;

View File

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

View File

@ -16,74 +16,41 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#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 <QTimer>
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<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();
}
QTimer::singleShot(0, this, SLOT(updateCloseButton()));
}

View File

@ -19,46 +19,26 @@
#define WEBINSPECTORDOCKWIDGET_H
#include <QWebInspector>
#include <QDockWidget>
#include <QPointer>
#include <QHash>
#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<QWebPage*, QPointer<WebInspector> > m_inspectors;
void hideEvent(QHideEvent* event);
void resizeEvent(QResizeEvent* event);
QPointer<WebInspector> m_currentInspector;
ToolButton* m_closeButton;
};
#endif // WEBINSPECTORDOCKWIDGET_H

View File

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

View File

@ -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 <QWebFrame>
#include <QLabel>
#include <QTimer>
#include <QSplitter>
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();

View File

@ -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