1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

[Code] Make it possible to move TabbedWebView to other window.

This commit is contained in:
nowrep 2013-05-12 22:55:53 +02:00
parent 53890c9f0e
commit 16d5917d43
9 changed files with 69 additions and 33 deletions

View File

@ -32,7 +32,7 @@
// Got an idea how to determine it from kWebKitPart. // Got an idea how to determine it from kWebKitPart.
PopupWebPage::PopupWebPage(QWebPage::WebWindowType type, QupZilla* mainClass) PopupWebPage::PopupWebPage(QWebPage::WebWindowType type, QupZilla* mainClass)
: WebPage(mainClass) : WebPage()
, p_QupZilla(mainClass) , p_QupZilla(mainClass)
, m_type(type) , m_type(type)
, m_createNewWindow(false) , m_createNewWindow(false)
@ -54,6 +54,11 @@ PopupWebPage::PopupWebPage(QWebPage::WebWindowType type, QupZilla* mainClass)
QTimer::singleShot(0, this, SLOT(checkBehaviour())); QTimer::singleShot(0, this, SLOT(checkBehaviour()));
} }
QupZilla* PopupWebPage::mainWindow() const
{
return p_QupZilla;
}
void PopupWebPage::slotGeometryChangeRequested(const QRect &rect) void PopupWebPage::slotGeometryChangeRequested(const QRect &rect)
{ {
if (rect.isValid()) { if (rect.isValid()) {

View File

@ -29,9 +29,7 @@ class QT_QUPZILLA_EXPORT PopupWebPage : public WebPage
public: public:
explicit PopupWebPage(WebWindowType type, QupZilla* mainClass); explicit PopupWebPage(WebWindowType type, QupZilla* mainClass);
signals: QupZilla* mainWindow() const;
public slots:
private slots: private slots:
void slotGeometryChangeRequested(const QRect &rect); void slotGeometryChangeRequested(const QRect &rect);

View File

@ -40,7 +40,6 @@
TabbedWebView::TabbedWebView(QupZilla* mainClass, WebTab* webTab) TabbedWebView::TabbedWebView(QupZilla* mainClass, WebTab* webTab)
: WebView(webTab) : WebView(webTab)
, p_QupZilla(mainClass) , p_QupZilla(mainClass)
, m_tabWidget(p_QupZilla->tabWidget())
, m_webTab(webTab) , m_webTab(webTab)
, m_menu(new Menu(this)) , m_menu(new Menu(this))
, m_mouseTrack(false) , m_mouseTrack(false)
@ -54,7 +53,6 @@ TabbedWebView::TabbedWebView(QupZilla* mainClass, WebTab* webTab)
connect(this, SIGNAL(iconChanged()), this, SLOT(showIcon())); connect(this, SIGNAL(iconChanged()), this, SLOT(showIcon()));
connect(this, SIGNAL(statusBarMessage(QString)), p_QupZilla->statusBar(), SLOT(showMessage(QString))); connect(this, SIGNAL(statusBarMessage(QString)), p_QupZilla->statusBar(), SLOT(showMessage(QString)));
connect(p_QupZilla, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool))); connect(p_QupZilla, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
// Tracking mouse also on tabs created in fullscreen // Tracking mouse also on tabs created in fullscreen
@ -83,7 +81,7 @@ WebTab* TabbedWebView::webTab() const
TabWidget* TabbedWebView::tabWidget() const TabWidget* TabbedWebView::tabWidget() const
{ {
return m_tabWidget; return p_QupZilla->tabWidget();
} }
QString TabbedWebView::getIp() const QString TabbedWebView::getIp() const
@ -93,7 +91,7 @@ QString TabbedWebView::getIp() const
bool TabbedWebView::isCurrent() bool TabbedWebView::isCurrent()
{ {
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_tabWidget->currentIndex())); WebTab* webTab = qobject_cast<WebTab*>(tabWidget()->widget(tabWidget()->currentIndex()));
if (!webTab) { if (!webTab) {
return false; return false;
} }
@ -131,10 +129,10 @@ void TabbedWebView::userLoadAction(const QUrl &url)
void TabbedWebView::slotLoadStarted() void TabbedWebView::slotLoadStarted()
{ {
m_tabWidget->startTabAnimation(tabIndex()); tabWidget()->startTabAnimation(tabIndex());
if (title().isNull()) { if (title().isNull()) {
m_tabWidget->setTabText(tabIndex(), tr("Loading...")); tabWidget()->setTabText(tabIndex(), tr("Loading..."));
} }
m_currentIp.clear(); m_currentIp.clear();
@ -142,7 +140,7 @@ void TabbedWebView::slotLoadStarted()
void TabbedWebView::slotLoadFinished() void TabbedWebView::slotLoadFinished()
{ {
m_tabWidget->stopTabAnimation(tabIndex()); tabWidget()->stopTabAnimation(tabIndex());
showIcon(); showIcon();
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo))); QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
@ -173,7 +171,7 @@ void TabbedWebView::titleChanged()
p_QupZilla->setWindowTitle(tr("%1 - QupZilla").arg(t)); p_QupZilla->setWindowTitle(tr("%1 - QupZilla").arg(t));
} }
m_tabWidget->setTabText(tabIndex(), t); tabWidget()->setTabText(tabIndex(), t);
} }
void TabbedWebView::showIcon() void TabbedWebView::showIcon()
@ -187,7 +185,7 @@ void TabbedWebView::showIcon()
icon_ = qIconProvider->emptyWebIcon(); icon_ = qIconProvider->emptyWebIcon();
} }
m_tabWidget->setTabIcon(tabIndex(), icon_); tabWidget()->setTabIcon(tabIndex(), icon_);
} }
void TabbedWebView::linkHovered(const QString &link, const QString &title, const QString &content) void TabbedWebView::linkHovered(const QString &link, const QString &title, const QString &content)
@ -207,7 +205,26 @@ void TabbedWebView::linkHovered(const QString &link, const QString &title, const
int TabbedWebView::tabIndex() const int TabbedWebView::tabIndex() const
{ {
return m_tabWidget->indexOf(m_webTab); return tabWidget()->indexOf(m_webTab);
}
QupZilla* TabbedWebView::mainWindow() const
{
return p_QupZilla;
}
void TabbedWebView::moveToWindow(QupZilla* window)
{
disconnect(this, SIGNAL(statusBarMessage(QString)), p_QupZilla->statusBar(), SLOT(showMessage(QString)));
disconnect(p_QupZilla, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
p_QupZilla = window;
connect(this, SIGNAL(statusBarMessage(QString)), p_QupZilla->statusBar(), SLOT(showMessage(QString)));
connect(p_QupZilla, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
// Tracking mouse also on tabs created in fullscreen
trackMouse(p_QupZilla->isFullScreen());
} }
QWidget* TabbedWebView::overlayForJsAlert() QWidget* TabbedWebView::overlayForJsAlert()
@ -259,17 +276,17 @@ void TabbedWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag pos
req.setRawHeader("Referer", url().toEncoded()); req.setRawHeader("Referer", url().toEncoded());
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1")); req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
m_tabWidget->addView(req, position); tabWidget()->addView(req, position);
} }
void TabbedWebView::openNewTab() void TabbedWebView::openNewTab()
{ {
m_tabWidget->addView(QUrl()); tabWidget()->addView(QUrl());
} }
void TabbedWebView::setAsCurrentTab() void TabbedWebView::setAsCurrentTab()
{ {
m_tabWidget->setCurrentWidget(m_webTab); tabWidget()->setCurrentWidget(m_webTab);
} }
void TabbedWebView::mouseMoveEvent(QMouseEvent* event) void TabbedWebView::mouseMoveEvent(QMouseEvent* event)

View File

@ -45,6 +45,9 @@ public:
QString getIp() const; QString getIp() const;
int tabIndex() const; int tabIndex() const;
QupZilla* mainWindow() const;
void moveToWindow(QupZilla* window);
QWidget* overlayForJsAlert(); QWidget* overlayForJsAlert();
void disconnectObjects(); void disconnectObjects();
@ -85,13 +88,10 @@ private:
bool isCurrent(); bool isCurrent();
QupZilla* p_QupZilla; QupZilla* p_QupZilla;
TabWidget* m_tabWidget;
QString m_currentIp;
WebTab* m_webTab; WebTab* m_webTab;
Menu* m_menu; Menu* m_menu;
QString m_currentIp;
bool m_mouseTrack; bool m_mouseTrack;
}; };

View File

@ -65,9 +65,8 @@ QUrl WebPage::s_lastUnsupportedUrl;
QTime WebPage::s_lastUnsupportedUrlTime; QTime WebPage::s_lastUnsupportedUrlTime;
QList<WebPage*> WebPage::s_livingPages; QList<WebPage*> WebPage::s_livingPages;
WebPage::WebPage(QupZilla* mainClass) WebPage::WebPage(QObject* parent)
: QWebPage() : QWebPage(parent)
, p_QupZilla(mainClass)
, m_view(0) , m_view(0)
, m_speedDial(mApp->plugins()->speedDial()) , m_speedDial(mApp->plugins()->speedDial())
, m_fileWatcher(0) , m_fileWatcher(0)
@ -548,7 +547,15 @@ void WebPage::populateNetworkRequest(QNetworkRequest &request)
QWebPage* WebPage::createWindow(QWebPage::WebWindowType type) QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
{ {
return new PopupWebPage(type, p_QupZilla); if (m_view) {
return new PopupWebPage(type, m_view->mainWindow());
}
if (PopupWebPage* popupPage = qobject_cast<PopupWebPage*>(this)) {
return new PopupWebPage(type, popupPage->mainWindow());
}
return 0;
} }
QObject* WebPage::createPlugin(const QString &classid, const QUrl &url, QObject* WebPage::createPlugin(const QString &classid, const QUrl &url,
@ -558,8 +565,8 @@ QObject* WebPage::createPlugin(const QString &classid, const QUrl &url,
Q_UNUSED(paramNames) Q_UNUSED(paramNames)
Q_UNUSED(paramValues) Q_UNUSED(paramValues)
if (classid == QLatin1String("RecoveryWidget") && mApp->restoreManager()) { if (classid == QLatin1String("RecoveryWidget") && mApp->restoreManager() && m_view) {
return new RecoveryWidget(qobject_cast<WebView*>(view()), p_QupZilla); return new RecoveryWidget(m_view, m_view->mainWindow());
} }
else { else {
mainFrame()->load(QUrl("qupzilla:start")); mainFrame()->load(QUrl("qupzilla:start"));
@ -787,7 +794,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
WebView* view = qobject_cast<WebView*>(popupPage->view()); WebView* view = qobject_cast<WebView*>(popupPage->view());
if (view) { if (view) {
// Closing blocked popup // Closing blocked popup
p_QupZilla->adBlockIcon()->popupBlocked(rule, exOption->url); popupPage->mainWindow()->adBlockIcon()->popupBlocked(rule, exOption->url);
view->closeView(); view->closeView();
} }
} }

View File

@ -48,7 +48,7 @@ public:
} }
}; };
WebPage(QupZilla* mainClass); WebPage(QObject* parent = 0);
~WebPage(); ~WebPage();
QUrl url() const; QUrl url() const;
@ -129,7 +129,6 @@ private:
static QTime s_lastUnsupportedUrlTime; static QTime s_lastUnsupportedUrlTime;
static QList<WebPage*> s_livingPages; static QList<WebPage*> s_livingPages;
QupZilla* p_QupZilla;
NetworkManagerProxy* m_networkProxy; NetworkManagerProxy* m_networkProxy;
TabbedWebView* m_view; TabbedWebView* m_view;
SpeedDial* m_speedDial; SpeedDial* m_speedDial;

View File

@ -107,7 +107,7 @@ WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar)
m_view = new TabbedWebView(p_QupZilla, this); m_view = new TabbedWebView(p_QupZilla, this);
m_view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); m_view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
WebPage* page = new WebPage(p_QupZilla); WebPage* page = new WebPage;
m_view->setWebPage(page); m_view->setWebPage(page);
m_layout->addWidget(m_view); m_layout->addWidget(m_view);
@ -176,6 +176,14 @@ QWebHistory* WebTab::history() const
return m_view->history(); return m_view->history();
} }
void WebTab::moveToWindow(QupZilla* window)
{
p_QupZilla = window;
m_view->moveToWindow(p_QupZilla);
//m_view->page()->moveToWindow(p_QupZilla);
}
void WebTab::setHistoryData(const QByteArray &data) void WebTab::setHistoryData(const QByteArray &data)
{ {
QDataStream historyStream(data); QDataStream historyStream(data);

View File

@ -64,6 +64,8 @@ public:
QIcon icon() const; QIcon icon() const;
QWebHistory* history() const; QWebHistory* history() const;
void moveToWindow(QupZilla* window);
void setHistoryData(const QByteArray &data); void setHistoryData(const QByteArray &data);
QByteArray historyData() const; QByteArray historyData() const;

View File

@ -32,8 +32,8 @@
- with width, height, left and top - with width, height, left and top
</p> </p>
<p> <p>
<a href="javascript:window.open('popup.html', '_blank', 'menubar=yes')">Popup 6</a> <a href="javascript:window.open('popupwindows.html', '_blank', 'menubar=yes')">Popup 6</a>
- with menubar - with menubar (popupwindows.html)
</p> </p>
<p> <p>
<a href="javascript:window.open('http://blog.qupzilla.com', '_blank', 'status=yes')">Popup 7</a> <a href="javascript:window.open('http://blog.qupzilla.com', '_blank', 'status=yes')">Popup 7</a>