mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
[WebTab] More cleanup in detach/attach code.
TabbedWebView can now be used with null BrowserWindow pointer.
This commit is contained in:
parent
61c1b8d8a1
commit
5c2c90ae6d
@ -362,7 +362,7 @@ int TabWidget::addView(const LoadRequest &req, const QString &title, const Qz::N
|
||||
m_locationBars->addWidget(webTab->locationBar());
|
||||
|
||||
int index = insertTab(position == -1 ? count() : position, webTab, QString(), pinned);
|
||||
webTab->attach(m_window, m_tabBar);
|
||||
webTab->attach(m_window);
|
||||
|
||||
if (!title.isEmpty()) {
|
||||
m_tabBar->setTabText(index, title);
|
||||
@ -426,7 +426,7 @@ int TabWidget::addView(WebTab* tab)
|
||||
{
|
||||
m_locationBars->addWidget(tab->locationBar());
|
||||
int index = addTab(tab, QString());
|
||||
tab->attach(m_window, m_tabBar);
|
||||
tab->attach(m_window);
|
||||
|
||||
connect(tab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
||||
connect(tab->webView(), SIGNAL(changed()), this, SIGNAL(changed()));
|
||||
|
@ -17,7 +17,6 @@
|
||||
* ============================================================ */
|
||||
#include "webpage.h"
|
||||
#include "tabbedwebview.h"
|
||||
#include "tabwidget.h"
|
||||
#include "browserwindow.h"
|
||||
#include "pluginproxy.h"
|
||||
#include "downloadmanager.h"
|
||||
@ -579,7 +578,7 @@ void WebPage::populateNetworkRequest(QNetworkRequest &request)
|
||||
QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
|
||||
{
|
||||
if (m_view) {
|
||||
return new PopupWebPage(type, m_view->mainWindow());
|
||||
return new PopupWebPage(type, m_view->browserWindow());
|
||||
}
|
||||
|
||||
if (PopupWebPage* popupPage = qobject_cast<PopupWebPage*>(this)) {
|
||||
@ -597,7 +596,7 @@ QObject* WebPage::createPlugin(const QString &classid, const QUrl &url,
|
||||
Q_UNUSED(paramValues)
|
||||
|
||||
if (classid == QLatin1String("RecoveryWidget") && mApp->restoreManager() && m_view) {
|
||||
return new RecoveryWidget(m_view, m_view->mainWindow());
|
||||
return new RecoveryWidget(m_view, m_view->browserWindow());
|
||||
}
|
||||
else {
|
||||
mainFrame()->load(QUrl("qupzilla:start"));
|
||||
|
@ -15,7 +15,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
#include "webview.h"
|
||||
#include "webpage.h"
|
||||
#include "mainapplication.h"
|
||||
|
@ -38,9 +38,9 @@
|
||||
#include <QWebFrame>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
TabbedWebView::TabbedWebView(BrowserWindow* window, WebTab* webTab)
|
||||
TabbedWebView::TabbedWebView(WebTab* webTab)
|
||||
: WebView(webTab)
|
||||
, m_window(window)
|
||||
, m_window(0)
|
||||
, m_webTab(webTab)
|
||||
, m_menu(new Menu(this))
|
||||
{
|
||||
@ -50,11 +50,6 @@ TabbedWebView::TabbedWebView(BrowserWindow* window, WebTab* webTab)
|
||||
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
|
||||
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished()));
|
||||
connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl)));
|
||||
connect(this, SIGNAL(statusBarMessage(QString)), m_window->statusBar(), SLOT(showMessage(QString)));
|
||||
}
|
||||
|
||||
TabbedWebView::~TabbedWebView()
|
||||
{
|
||||
}
|
||||
|
||||
void TabbedWebView::setWebPage(WebPage* page)
|
||||
@ -66,9 +61,27 @@ void TabbedWebView::setWebPage(WebPage* page)
|
||||
connect(page, SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(linkHovered(QString,QString,QString)));
|
||||
}
|
||||
|
||||
BrowserWindow* TabbedWebView::browserWindow() const
|
||||
{
|
||||
return m_window;
|
||||
}
|
||||
|
||||
void TabbedWebView::setBrowserWindow(BrowserWindow* window)
|
||||
{
|
||||
if (m_window) {
|
||||
disconnect(this, SIGNAL(statusBarMessage(QString)), m_window->statusBar(), SLOT(showMessage(QString)));
|
||||
}
|
||||
|
||||
m_window = window;
|
||||
|
||||
if (m_window) {
|
||||
connect(this, SIGNAL(statusBarMessage(QString)), m_window->statusBar(), SLOT(showMessage(QString)));
|
||||
}
|
||||
}
|
||||
|
||||
void TabbedWebView::inspectElement()
|
||||
{
|
||||
m_window->showWebInspector();
|
||||
m_webTab->showWebInspector();
|
||||
triggerPageAction(QWebPage::InspectElement);
|
||||
}
|
||||
|
||||
@ -79,7 +92,8 @@ WebTab* TabbedWebView::webTab() const
|
||||
|
||||
TabWidget* TabbedWebView::tabWidget() const
|
||||
{
|
||||
return m_window->tabWidget();
|
||||
// FIXME:!!
|
||||
return m_window ? m_window->tabWidget() : 0;
|
||||
}
|
||||
|
||||
QString TabbedWebView::getIp() const
|
||||
@ -89,7 +103,7 @@ QString TabbedWebView::getIp() const
|
||||
|
||||
void TabbedWebView::urlChanged(const QUrl &url)
|
||||
{
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
if (m_webTab->isCurrentTab() && m_window) {
|
||||
m_window->navigationBar()->refreshHistory();
|
||||
}
|
||||
|
||||
@ -102,7 +116,7 @@ void TabbedWebView::slotLoadProgress(int prog)
|
||||
{
|
||||
Q_UNUSED(prog)
|
||||
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
if (m_webTab->isCurrentTab() && m_window) {
|
||||
m_window->updateLoadingActions();
|
||||
}
|
||||
}
|
||||
@ -127,7 +141,7 @@ void TabbedWebView::slotLoadFinished()
|
||||
{
|
||||
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
|
||||
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
if (m_webTab->isCurrentTab() && m_window) {
|
||||
m_window->updateLoadingActions();
|
||||
}
|
||||
}
|
||||
@ -150,7 +164,7 @@ void TabbedWebView::linkHovered(const QString &link, const QString &title, const
|
||||
Q_UNUSED(title)
|
||||
Q_UNUSED(content)
|
||||
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
if (m_webTab->isCurrentTab() && m_window) {
|
||||
if (link.isEmpty()) {
|
||||
m_window->statusBarMessage()->clearMessage();
|
||||
}
|
||||
@ -169,20 +183,6 @@ int TabbedWebView::tabIndex() const
|
||||
return m_webTab->tabIndex();
|
||||
}
|
||||
|
||||
BrowserWindow* TabbedWebView::mainWindow() const
|
||||
{
|
||||
return m_window;
|
||||
}
|
||||
|
||||
void TabbedWebView::moveToWindow(BrowserWindow* window)
|
||||
{
|
||||
if (m_window != window) {
|
||||
disconnect(this, SIGNAL(statusBarMessage(QString)), m_window->statusBar(), SLOT(showMessage(QString)));
|
||||
m_window = window;
|
||||
connect(this, SIGNAL(statusBarMessage(QString)), m_window->statusBar(), SLOT(showMessage(QString)));
|
||||
}
|
||||
}
|
||||
|
||||
QWidget* TabbedWebView::overlayWidget()
|
||||
{
|
||||
return m_webTab;
|
||||
@ -196,7 +196,7 @@ void TabbedWebView::contextMenuEvent(QContextMenuEvent* event)
|
||||
|
||||
createContextMenu(m_menu, hitTest, event->pos());
|
||||
|
||||
if (!hitTest.isContentEditable() && !hitTest.isContentSelected()) {
|
||||
if (!hitTest.isContentEditable() && !hitTest.isContentSelected() && m_window) {
|
||||
m_menu->addAction(m_window->adBlockIcon()->menuAction());
|
||||
}
|
||||
|
||||
@ -227,9 +227,11 @@ void TabbedWebView::openNewTab()
|
||||
|
||||
void TabbedWebView::loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position)
|
||||
{
|
||||
int index = tabWidget()->addView(QUrl(), position);
|
||||
m_window->weView(index)->webTab()->locationBar()->showUrl(req.url());
|
||||
m_window->weView(index)->load(req);
|
||||
if (m_window) {
|
||||
int index = tabWidget()->addView(QUrl(), position);
|
||||
m_window->weView(index)->webTab()->locationBar()->showUrl(req.url());
|
||||
m_window->weView(index)->load(req);
|
||||
}
|
||||
}
|
||||
|
||||
void TabbedWebView::setAsCurrentTab()
|
||||
@ -239,7 +241,7 @@ void TabbedWebView::setAsCurrentTab()
|
||||
|
||||
void TabbedWebView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
if (m_window->isFullScreen()) {
|
||||
if (m_window && m_window->isFullScreen()) {
|
||||
if (m_window->fullScreenNavigationVisible()) {
|
||||
m_window->hideNavigationWithFullScreen();
|
||||
}
|
||||
|
@ -34,10 +34,12 @@ class QUPZILLA_EXPORT TabbedWebView : public WebView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TabbedWebView(BrowserWindow* window, WebTab* webTab);
|
||||
~TabbedWebView();
|
||||
explicit TabbedWebView(WebTab* webTab);
|
||||
|
||||
void setWebPage(WebPage* pag);
|
||||
void setWebPage(WebPage* page);
|
||||
|
||||
BrowserWindow* browserWindow() const;
|
||||
void setBrowserWindow(BrowserWindow* window);
|
||||
|
||||
WebTab* webTab() const;
|
||||
TabWidget* tabWidget() const;
|
||||
@ -45,9 +47,6 @@ public:
|
||||
QString getIp() const;
|
||||
int tabIndex() const;
|
||||
|
||||
BrowserWindow* mainWindow() const;
|
||||
void moveToWindow(BrowserWindow* window);
|
||||
|
||||
QWidget* overlayWidget();
|
||||
|
||||
signals:
|
||||
@ -82,7 +81,6 @@ private:
|
||||
Menu* m_menu;
|
||||
|
||||
QString m_currentIp;
|
||||
|
||||
};
|
||||
|
||||
#endif // TABBEDWEBVIEW_H
|
||||
|
@ -97,9 +97,10 @@ WebTab::WebTab(BrowserWindow* window)
|
||||
// This fixes background of pages with dark themes
|
||||
setStyleSheet("#webtab {background-color:white;}");
|
||||
|
||||
m_webView = new TabbedWebView(m_window, this);
|
||||
m_webView = new TabbedWebView(this);
|
||||
m_webView->setBrowserWindow(m_window);
|
||||
m_webView->setWebPage(new WebPage(this));
|
||||
m_webView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
m_webView->setWebPage(new WebPage(m_webView));
|
||||
|
||||
m_locationBar = new LocationBar(m_window);
|
||||
m_locationBar->setWebView(m_webView);
|
||||
@ -178,19 +179,24 @@ void WebTab::detach()
|
||||
// Remove icon from tab
|
||||
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), 0);
|
||||
|
||||
// Remove the tab from tabbar
|
||||
setParent(0);
|
||||
// Remove the locationbar from window
|
||||
m_locationBar->setParent(this);
|
||||
// Detach TabbedWebView
|
||||
m_webView->setBrowserWindow(0);
|
||||
|
||||
// WebTab is now standalone widget
|
||||
m_window = 0;
|
||||
m_tabBar = 0;
|
||||
|
||||
setParent(0);
|
||||
m_locationBar->setParent(this);
|
||||
}
|
||||
|
||||
void WebTab::attach(BrowserWindow* window, TabBar* tabBar)
|
||||
void WebTab::attach(BrowserWindow* window)
|
||||
{
|
||||
m_window = window;
|
||||
m_tabBar = tabBar;
|
||||
m_tabBar = m_window->tabWidget()->getTabBar();
|
||||
|
||||
m_webView->moveToWindow(m_window);
|
||||
m_webView->setBrowserWindow(m_window);
|
||||
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), m_tabIcon);
|
||||
m_tabBar->setTabText(tabIndex(), title());
|
||||
}
|
||||
@ -207,7 +213,6 @@ QByteArray WebTab::historyData() const
|
||||
QByteArray historyArray;
|
||||
QDataStream historyStream(&historyArray, QIODevice::WriteOnly);
|
||||
historyStream << *m_webView->history();
|
||||
|
||||
return historyArray;
|
||||
}
|
||||
else {
|
||||
@ -329,6 +334,7 @@ QPixmap WebTab::renderTabPreview()
|
||||
p.end();
|
||||
|
||||
page->setViewportSize(oldSize);
|
||||
|
||||
// Restore also scrollbar positions, to prevent messing scrolling to anchor links
|
||||
page->mainFrame()->setScrollBarValue(Qt::Vertical, originalScrollPosition.y());
|
||||
page->mainFrame()->setScrollBarValue(Qt::Horizontal, originalScrollPosition.x());
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
QWebHistory* history() const;
|
||||
|
||||
void detach();
|
||||
void attach(BrowserWindow* window, TabBar* tabBar);
|
||||
void attach(BrowserWindow* window);
|
||||
|
||||
void setHistoryData(const QByteArray &data);
|
||||
QByteArray historyData() const;
|
||||
|
Loading…
Reference in New Issue
Block a user