mirror of
https://invent.kde.org/network/falkon.git
synced 2024-09-21 17:52:10 +02:00
[WebTab] Move more code into WebTab, instead of handling in TabWidget/TabBar
This also fixes showing tab icon after detaching tab
This commit is contained in:
parent
27a3781ed0
commit
3d23f3eb02
|
@ -533,7 +533,7 @@ TabbedWebView* BrowserWindow::weView(int index) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
return webTab->view();
|
||||
return webTab->webView();
|
||||
}
|
||||
|
||||
LocationBar* BrowserWindow::locationBar() const
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#define QUPZILLA_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QPointer>
|
||||
#include <QUrl>
|
||||
|
||||
#include "restoremanager.h"
|
||||
|
|
|
@ -347,6 +347,14 @@ int TabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const
|
|||
return -1;
|
||||
}
|
||||
|
||||
WebTab* TabBar::webTab(int index) const
|
||||
{
|
||||
if (index == -1) {
|
||||
return qobject_cast<WebTab*>(m_tabWidget->widget(currentIndex()));
|
||||
}
|
||||
return qobject_cast<WebTab*>(m_tabWidget->widget(index));
|
||||
}
|
||||
|
||||
void TabBar::showCloseButton(int index)
|
||||
{
|
||||
if (!validIndex(index)) {
|
||||
|
@ -479,6 +487,23 @@ void TabBar::restoreTabTextColor(int index)
|
|||
setTabTextColor(index, m_originalTabTextColor);
|
||||
}
|
||||
|
||||
void TabBar::setTabText(int index, const QString &text)
|
||||
{
|
||||
QString tabText = text;
|
||||
|
||||
// Avoid Alt+letter shortcuts
|
||||
tabText.replace(QLatin1Char('&'), QLatin1String("&&"));
|
||||
|
||||
if (WebTab* tab = webTab(index)) {
|
||||
if (tab->isPinned()) {
|
||||
tabText.clear();
|
||||
}
|
||||
}
|
||||
|
||||
setTabToolTip(index, text);
|
||||
ComboTabBar::setTabText(index, tabText);
|
||||
}
|
||||
|
||||
void TabBar::showTabPreview(bool delayed)
|
||||
{
|
||||
if (!m_showTabPreviews) {
|
||||
|
@ -714,7 +739,7 @@ void TabBar::dropEvent(QDropEvent* event)
|
|||
else {
|
||||
WebTab* tab = m_window->weView(index)->webTab();
|
||||
if (tab->isRestored()) {
|
||||
tab->view()->load(mime->urls().at(0));
|
||||
tab->webView()->load(mime->urls().at(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
class BrowserWindow;
|
||||
class TabWidget;
|
||||
class TabPreview;
|
||||
class WebTab;
|
||||
|
||||
class QUPZILLA_EXPORT TabBar : public ComboTabBar
|
||||
{
|
||||
|
@ -42,6 +43,7 @@ public:
|
|||
void overrideTabTextColor(int index, QColor color);
|
||||
void restoreTabTextColor(int index);
|
||||
|
||||
void setTabText(int index, const QString &text);
|
||||
void updatePinnedTabCloseButton(int index);
|
||||
|
||||
void wheelEvent(QWheelEvent* event);
|
||||
|
@ -96,6 +98,7 @@ private:
|
|||
|
||||
QSize tabSizeHint(int index, bool fast) const;
|
||||
int comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const;
|
||||
WebTab* webTab(int index = -1) const;
|
||||
|
||||
BrowserWindow* m_window;
|
||||
TabWidget* m_tabWidget;
|
||||
|
|
|
@ -90,19 +90,9 @@ QString TabbedWebView::getIp() const
|
|||
return m_currentIp;
|
||||
}
|
||||
|
||||
bool TabbedWebView::isCurrent()
|
||||
{
|
||||
WebTab* webTab = qobject_cast<WebTab*>(tabWidget()->widget(tabWidget()->currentIndex()));
|
||||
if (!webTab) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (webTab->view() == this);
|
||||
}
|
||||
|
||||
void TabbedWebView::urlChanged(const QUrl &url)
|
||||
{
|
||||
if (isCurrent()) {
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
m_window->navigationBar()->refreshHistory();
|
||||
}
|
||||
|
||||
|
@ -115,7 +105,7 @@ void TabbedWebView::loadProgress(int prog)
|
|||
{
|
||||
Q_UNUSED(prog)
|
||||
|
||||
if (isCurrent()) {
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
m_window->updateLoadingActions();
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +121,7 @@ void TabbedWebView::userLoadAction(const QUrl &url)
|
|||
void TabbedWebView::slotLoadStarted()
|
||||
{
|
||||
if (title().isNull()) {
|
||||
tabWidget()->setTabText(tabIndex(), tr("Loading..."));
|
||||
m_webTab->setTabTitle(tr("Loading..."));
|
||||
}
|
||||
|
||||
m_currentIp.clear();
|
||||
|
@ -141,7 +131,7 @@ void TabbedWebView::slotLoadFinished()
|
|||
{
|
||||
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
|
||||
|
||||
if (isCurrent()) {
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
m_window->updateLoadingActions();
|
||||
}
|
||||
}
|
||||
|
@ -154,20 +144,18 @@ void TabbedWebView::setIp(const QHostInfo &info)
|
|||
|
||||
m_currentIp = QString("%1 (%2)").arg(info.hostName(), info.addresses().at(0).toString());
|
||||
|
||||
if (isCurrent()) {
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
emit ipChanged(m_currentIp);
|
||||
}
|
||||
}
|
||||
|
||||
void TabbedWebView::titleChanged()
|
||||
{
|
||||
const QString t = title();
|
||||
|
||||
if (isCurrent()) {
|
||||
m_window->setWindowTitle(tr("%1 - QupZilla").arg(t));
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
m_window->setWindowTitle(tr("%1 - QupZilla").arg(title()));
|
||||
}
|
||||
|
||||
tabWidget()->setTabText(tabIndex(), t);
|
||||
m_webTab->setTabTitle(title());
|
||||
}
|
||||
|
||||
void TabbedWebView::linkHovered(const QString &link, const QString &title, const QString &content)
|
||||
|
@ -175,7 +163,7 @@ void TabbedWebView::linkHovered(const QString &link, const QString &title, const
|
|||
Q_UNUSED(title)
|
||||
Q_UNUSED(content)
|
||||
|
||||
if (isCurrent()) {
|
||||
if (m_webTab->isCurrentTab()) {
|
||||
if (link.isEmpty()) {
|
||||
m_window->statusBarMessage()->clearMessage();
|
||||
}
|
||||
|
|
|
@ -83,8 +83,6 @@ private:
|
|||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
|
||||
bool isCurrent();
|
||||
|
||||
BrowserWindow* m_window;
|
||||
WebTab* m_webTab;
|
||||
Menu* m_menu;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* ============================================================ */
|
||||
#include "tabicon.h"
|
||||
#include "webtab.h"
|
||||
#include "iconprovider.h"
|
||||
#include "tabbedwebview.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
@ -39,15 +40,17 @@ TabIcon::TabIcon(QWidget* parent)
|
|||
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateAnimationFrame()));
|
||||
|
||||
resize(16, 16);
|
||||
|
||||
setIcon(IconProvider::emptyWebIcon());
|
||||
}
|
||||
|
||||
void TabIcon::setWebTab(WebTab* tab)
|
||||
{
|
||||
m_tab = tab;
|
||||
|
||||
connect(m_tab->view(), SIGNAL(loadStarted()), this, SLOT(showLoadingAnimation()));
|
||||
connect(m_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(hideLoadingAnimation()));
|
||||
connect(m_tab->view(), SIGNAL(iconChanged()), this, SLOT(showIcon()));
|
||||
connect(m_tab->webView(), SIGNAL(loadStarted()), this, SLOT(showLoadingAnimation()));
|
||||
connect(m_tab->webView(), SIGNAL(loadFinished(bool)), this, SLOT(hideLoadingAnimation()));
|
||||
connect(m_tab->webView(), SIGNAL(iconChanged()), this, SLOT(showIcon()));
|
||||
|
||||
showIcon();
|
||||
}
|
||||
|
|
|
@ -25,27 +25,21 @@
|
|||
#include "webtab.h"
|
||||
#include "clickablelabel.h"
|
||||
#include "closedtabsmanager.h"
|
||||
#include "progressbar.h"
|
||||
#include "navigationbar.h"
|
||||
#include "locationbar.h"
|
||||
#include "websearchbar.h"
|
||||
#include "settings.h"
|
||||
#include "datapaths.h"
|
||||
#include "qzsettings.h"
|
||||
#include "qztools.h"
|
||||
#include "qtwin.h"
|
||||
#include "tabicon.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTimer>
|
||||
#include <QMovie>
|
||||
#include <QMimeData>
|
||||
#include <QStackedWidget>
|
||||
#include <QMouseEvent>
|
||||
#include <QWebHistory>
|
||||
#include <QWebFrame>
|
||||
#include <QClipboard>
|
||||
#include <QFile>
|
||||
#include <QScrollArea>
|
||||
|
||||
AddTabButton::AddTabButton(TabWidget* tabWidget, TabBar* tabBar)
|
||||
: ToolButton(tabBar)
|
||||
|
@ -235,15 +229,7 @@ WebTab* TabWidget::weTab(int index)
|
|||
|
||||
TabIcon* TabWidget::tabIcon(int index)
|
||||
{
|
||||
TabIcon* icon = qobject_cast<TabIcon*>(m_tabBar->tabButton(index, m_tabBar->iconButtonPosition()));
|
||||
|
||||
if (!icon) {
|
||||
icon = new TabIcon(this);
|
||||
icon->setWebTab(weTab(index));
|
||||
m_tabBar->setTabButton(index, m_tabBar->iconButtonPosition(), icon);
|
||||
}
|
||||
|
||||
return icon;
|
||||
return weTab(index)->tabIcon();
|
||||
}
|
||||
|
||||
bool TabWidget::validIndex(int index) const
|
||||
|
@ -413,23 +399,13 @@ int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewT
|
|||
}
|
||||
}
|
||||
|
||||
LocationBar* locBar = new LocationBar(m_window);
|
||||
m_locationBars->addWidget(locBar);
|
||||
int index;
|
||||
WebTab* webTab = new WebTab(m_window);
|
||||
webTab->locationBar()->showUrl(url);
|
||||
m_locationBars->addWidget(webTab->locationBar());
|
||||
|
||||
if (position == -1) {
|
||||
index = addTab(new WebTab(m_window, locBar), QString(), pinned);
|
||||
}
|
||||
else {
|
||||
index = insertTab(position, new WebTab(m_window, locBar), QString(), pinned);
|
||||
}
|
||||
|
||||
TabbedWebView* webView = weTab(index)->view();
|
||||
locBar->setWebView(webView);
|
||||
locBar->showUrl(url);
|
||||
|
||||
setTabText(index, title);
|
||||
setTabIcon(index, IconProvider::emptyWebIcon());
|
||||
int index = insertTab(position == -1 ? count() : position, webTab, QString(), pinned);
|
||||
webTab->setTabbed(index);
|
||||
webTab->setTabTitle(title);
|
||||
|
||||
if (openFlags & Qz::NT_SelectedTab) {
|
||||
setCurrentIndex(index);
|
||||
|
@ -438,13 +414,13 @@ int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewT
|
|||
m_lastBackgroundTabIndex = index;
|
||||
}
|
||||
|
||||
connect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
||||
connect(webView, SIGNAL(changed()), this, SIGNAL(changed()));
|
||||
connect(webView, SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
||||
connect(webTab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
||||
connect(webTab->webView(), SIGNAL(changed()), this, SIGNAL(changed()));
|
||||
connect(webTab->webView(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
||||
|
||||
if (url.isValid()) {
|
||||
req.setUrl(url);
|
||||
webView->load(req);
|
||||
webTab->webView()->load(req);
|
||||
}
|
||||
|
||||
if (selectLine && m_window->locationBar()->text().isEmpty()) {
|
||||
|
@ -459,10 +435,10 @@ int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewT
|
|||
WebTab* currentWebTab = weTab();
|
||||
// Workarounding invalid QWebPage::viewportSize() until QWebView is shown
|
||||
// Fixes invalid scrolling to anchor(#) links
|
||||
if (currentWebTab && currentWebTab->view()) {
|
||||
TabbedWebView* currentView = currentWebTab->view();
|
||||
webView->resize(currentView->size());
|
||||
webView->page()->setViewportSize(currentView->page()->viewportSize());
|
||||
if (currentWebTab && currentWebTab->webView()) {
|
||||
TabbedWebView* currentView = currentWebTab->webView();
|
||||
webTab->webView()->resize(currentView->size());
|
||||
webTab->webView()->page()->setViewportSize(currentView->page()->viewportSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -484,14 +460,12 @@ int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewT
|
|||
int TabWidget::addView(WebTab* tab)
|
||||
{
|
||||
m_locationBars->addWidget(tab->locationBar());
|
||||
tab->locationBar()->setWebView(tab->view());
|
||||
|
||||
int index = addTab(tab, QString());
|
||||
setTabText(index, tab->title());
|
||||
tab->setTabbed(index);
|
||||
|
||||
connect(tab->view(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
||||
connect(tab->view(), SIGNAL(changed()), this, SIGNAL(changed()));
|
||||
connect(tab->view(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
||||
connect(tab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
||||
connect(tab->webView(), SIGNAL(changed()), this, SIGNAL(changed()));
|
||||
connect(tab->webView(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
||||
|
||||
return index;
|
||||
}
|
||||
|
@ -517,7 +491,7 @@ void TabWidget::closeTab(int index, bool force)
|
|||
return;
|
||||
}
|
||||
|
||||
TabbedWebView* webView = webTab->view();
|
||||
TabbedWebView* webView = webTab->webView();
|
||||
|
||||
// Don't close restore page!
|
||||
if (!force && webView->url().toString() == QL1S("qupzilla:restore") && mApp->restoreManager()) {
|
||||
|
@ -612,34 +586,6 @@ void TabWidget::setCurrentIndex(int index)
|
|||
TabStackedWidget::setCurrentIndex(index);
|
||||
}
|
||||
|
||||
void TabWidget::setTabIcon(int index, const QIcon &icon)
|
||||
{
|
||||
if (!validIndex(index)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tabIcon(index)->setIcon(icon);
|
||||
}
|
||||
|
||||
void TabWidget::setTabText(int index, const QString &text)
|
||||
{
|
||||
if (!validIndex(index)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString newtext = text;
|
||||
newtext.replace(QLatin1Char('&'), QLatin1String("&&")); // Avoid Alt+letter shortcuts
|
||||
|
||||
if (WebTab* webTab = weTab(index)) {
|
||||
if (webTab->isPinned()) {
|
||||
newtext.clear();
|
||||
}
|
||||
}
|
||||
|
||||
setTabToolTip(index, text);
|
||||
TabStackedWidget::setTabText(index, newtext);
|
||||
}
|
||||
|
||||
void TabWidget::nextTab()
|
||||
{
|
||||
QKeyEvent fakeEvent(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::ControlModifier);
|
||||
|
@ -734,9 +680,9 @@ void TabWidget::detachTab(int index)
|
|||
}
|
||||
|
||||
m_locationBars->removeWidget(tab->locationBar());
|
||||
disconnect(tab->view(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
||||
disconnect(tab->view(), SIGNAL(changed()), this, SIGNAL(changed()));
|
||||
disconnect(tab->view(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
||||
disconnect(tab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
||||
disconnect(tab->webView(), SIGNAL(changed()), this, SIGNAL(changed()));
|
||||
disconnect(tab->webView(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
||||
|
||||
BrowserWindow* window = mApp->createWindow(Qz::BW_NewWindow);
|
||||
tab->moveToWindow(window);
|
||||
|
|
|
@ -79,8 +79,6 @@ public:
|
|||
void restorePinnedTabs();
|
||||
|
||||
void setCurrentIndex(int index);
|
||||
void setTabIcon(int index, const QIcon &icon);
|
||||
void setTabText(int index, const QString &text);
|
||||
|
||||
void nextTab();
|
||||
void previousTab();
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "tabbedwebview.h"
|
||||
#include "webpage.h"
|
||||
#include "tabbar.h"
|
||||
#include "tabicon.h"
|
||||
#include "tabwidget.h"
|
||||
#include "locationbar.h"
|
||||
#include "qztools.h"
|
||||
|
@ -30,7 +31,6 @@
|
|||
#include <QWebHistory>
|
||||
#include <QWebFrame>
|
||||
#include <QLabel>
|
||||
#include <QStyle>
|
||||
#include <QTimer>
|
||||
|
||||
static const int savedTabVersion = 1;
|
||||
|
@ -43,6 +43,11 @@ WebTab::SavedTab::SavedTab(WebTab* webTab)
|
|||
history = webTab->historyData();
|
||||
}
|
||||
|
||||
bool WebTab::SavedTab::isEmpty() const
|
||||
{
|
||||
return url.isEmpty();
|
||||
}
|
||||
|
||||
void WebTab::SavedTab::clear()
|
||||
{
|
||||
title.clear();
|
||||
|
@ -67,16 +72,6 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
|
|||
int version;
|
||||
stream >> version;
|
||||
|
||||
// Hack to ensure backwards compatibility
|
||||
if (version != savedTabVersion) {
|
||||
stream.device()->seek(stream.device()->pos() - sizeof(int));
|
||||
stream >> tab.title;
|
||||
stream >> tab.url;
|
||||
stream >> tab.icon;
|
||||
stream >> tab.history;
|
||||
return stream;
|
||||
}
|
||||
|
||||
QPixmap pixmap;
|
||||
stream >> tab.title;
|
||||
stream >> tab.url;
|
||||
|
@ -88,12 +83,11 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
|
|||
return stream;
|
||||
}
|
||||
|
||||
WebTab::WebTab(BrowserWindow* window, LocationBar* locationBar)
|
||||
WebTab::WebTab(BrowserWindow* window)
|
||||
: QWidget()
|
||||
, m_window(window)
|
||||
, m_navigationContainer(0)
|
||||
, m_locationBar(locationBar)
|
||||
, m_pinned(false)
|
||||
, m_tabBar(window->tabWidget()->getTabBar())
|
||||
, m_isPinned(false)
|
||||
, m_inspectorVisible(false)
|
||||
{
|
||||
setObjectName("webtab");
|
||||
|
@ -101,24 +95,30 @@ WebTab::WebTab(BrowserWindow* window, LocationBar* locationBar)
|
|||
// 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_locationBar = new LocationBar(m_window);
|
||||
m_locationBar->setWebView(m_webView);
|
||||
|
||||
m_tabIcon = new TabIcon(this);
|
||||
m_tabIcon->setWebTab(this);
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_layout->setSpacing(0);
|
||||
|
||||
m_view = new TabbedWebView(m_window, this);
|
||||
m_view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
WebPage* page = new WebPage;
|
||||
m_view->setWebPage(page);
|
||||
m_layout->addWidget(m_view);
|
||||
|
||||
m_layout->addWidget(m_webView);
|
||||
setLayout(m_layout);
|
||||
|
||||
connect(m_view, SIGNAL(showNotification(QWidget*)), this, SLOT(showNotification(QWidget*)));
|
||||
connect(m_webView, SIGNAL(showNotification(QWidget*)), this, SLOT(showNotification(QWidget*)));
|
||||
}
|
||||
|
||||
TabbedWebView* WebTab::view() const
|
||||
TabbedWebView* WebTab::webView() const
|
||||
{
|
||||
return m_view;
|
||||
return m_webView;
|
||||
}
|
||||
|
||||
void WebTab::setCurrentTab()
|
||||
|
@ -137,7 +137,7 @@ void WebTab::setCurrentTab()
|
|||
QUrl WebTab::url() const
|
||||
{
|
||||
if (isRestored()) {
|
||||
return m_view->url();
|
||||
return m_webView->url();
|
||||
}
|
||||
else {
|
||||
return m_savedTab.url;
|
||||
|
@ -147,7 +147,7 @@ QUrl WebTab::url() const
|
|||
QString WebTab::title() const
|
||||
{
|
||||
if (isRestored()) {
|
||||
return m_view->title();
|
||||
return m_webView->title();
|
||||
}
|
||||
else {
|
||||
return m_savedTab.title;
|
||||
|
@ -157,7 +157,7 @@ QString WebTab::title() const
|
|||
QIcon WebTab::icon() const
|
||||
{
|
||||
if (isRestored()) {
|
||||
return m_view->icon();
|
||||
return m_webView->icon();
|
||||
}
|
||||
else {
|
||||
return m_savedTab.icon;
|
||||
|
@ -166,20 +166,34 @@ QIcon WebTab::icon() const
|
|||
|
||||
QWebHistory* WebTab::history() const
|
||||
{
|
||||
return m_view->history();
|
||||
return m_webView->history();
|
||||
}
|
||||
|
||||
void WebTab::moveToWindow(BrowserWindow* window)
|
||||
{
|
||||
m_window = window;
|
||||
m_webView->moveToWindow(m_window);
|
||||
|
||||
m_view->moveToWindow(m_window);
|
||||
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), 0);
|
||||
m_tabIcon->setParent(0);
|
||||
}
|
||||
|
||||
void WebTab::setTabbed(int index)
|
||||
{
|
||||
m_tabBar->setTabButton(index, m_tabBar->iconButtonPosition(), m_tabIcon);
|
||||
m_tabBar->setTabText(index, title());
|
||||
}
|
||||
|
||||
void WebTab::setTabTitle(const QString &title)
|
||||
{
|
||||
|
||||
m_tabBar->setTabText(tabIndex(), title);
|
||||
}
|
||||
|
||||
void WebTab::setHistoryData(const QByteArray &data)
|
||||
{
|
||||
QDataStream historyStream(data);
|
||||
historyStream >> *m_view->history();
|
||||
historyStream >> *m_webView->history();
|
||||
}
|
||||
|
||||
QByteArray WebTab::historyData() const
|
||||
|
@ -187,7 +201,7 @@ QByteArray WebTab::historyData() const
|
|||
if (isRestored()) {
|
||||
QByteArray historyArray;
|
||||
QDataStream historyStream(&historyArray, QIODevice::WriteOnly);
|
||||
historyStream << *m_view->history();
|
||||
historyStream << *m_webView->history();
|
||||
|
||||
return historyArray;
|
||||
}
|
||||
|
@ -198,37 +212,37 @@ QByteArray WebTab::historyData() const
|
|||
|
||||
void WebTab::reload()
|
||||
{
|
||||
m_view->reload();
|
||||
m_webView->reload();
|
||||
}
|
||||
|
||||
void WebTab::stop()
|
||||
{
|
||||
m_view->stop();
|
||||
m_webView->stop();
|
||||
}
|
||||
|
||||
bool WebTab::isLoading() const
|
||||
{
|
||||
return m_view->isLoading();
|
||||
return m_webView->isLoading();
|
||||
}
|
||||
|
||||
bool WebTab::isPinned() const
|
||||
{
|
||||
return m_pinned;
|
||||
return m_isPinned;
|
||||
}
|
||||
|
||||
void WebTab::setPinned(bool state)
|
||||
{
|
||||
m_pinned = state;
|
||||
}
|
||||
|
||||
void WebTab::setLocationBar(LocationBar* bar)
|
||||
{
|
||||
m_locationBar = bar;
|
||||
m_isPinned = state;
|
||||
}
|
||||
|
||||
LocationBar* WebTab::locationBar() const
|
||||
{
|
||||
return m_locationBar.data();
|
||||
return m_locationBar;
|
||||
}
|
||||
|
||||
TabIcon* WebTab::tabIcon() const
|
||||
{
|
||||
return m_tabIcon;
|
||||
}
|
||||
|
||||
bool WebTab::inspectorVisible() const
|
||||
|
@ -241,11 +255,6 @@ void WebTab::setInspectorVisible(bool v)
|
|||
m_inspectorVisible = v;
|
||||
}
|
||||
|
||||
WebTab::SavedTab WebTab::savedTab() const
|
||||
{
|
||||
return m_savedTab;
|
||||
}
|
||||
|
||||
bool WebTab::isRestored() const
|
||||
{
|
||||
return m_savedTab.isEmpty();
|
||||
|
@ -257,12 +266,12 @@ void WebTab::restoreTab(const WebTab::SavedTab &tab)
|
|||
m_savedTab = tab;
|
||||
int index = tabIndex();
|
||||
|
||||
m_view->tabWidget()->setTabIcon(index, tab.icon);
|
||||
m_view->tabWidget()->setTabText(index, tab.title);
|
||||
m_locationBar.data()->showUrl(tab.url);
|
||||
m_tabBar->setTabText(index, tab.title);
|
||||
m_locationBar->showUrl(tab.url);
|
||||
m_tabIcon->setIcon(tab.icon);
|
||||
|
||||
if (!tab.url.isEmpty()) {
|
||||
QColor col = m_view->tabWidget()->getTabBar()->palette().text().color();
|
||||
QColor col = m_tabBar->palette().text().color();
|
||||
QColor newCol = col.lighter(250);
|
||||
|
||||
// It won't work for black color because (V) = 0
|
||||
|
@ -271,7 +280,7 @@ void WebTab::restoreTab(const WebTab::SavedTab &tab)
|
|||
newCol = Qt::gray;
|
||||
}
|
||||
|
||||
m_view->tabWidget()->getTabBar()->overrideTabTextColor(index, newCol);
|
||||
m_tabBar->overrideTabTextColor(index, newCol);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -281,10 +290,10 @@ void WebTab::restoreTab(const WebTab::SavedTab &tab)
|
|||
|
||||
void WebTab::p_restoreTab(const QUrl &url, const QByteArray &history)
|
||||
{
|
||||
m_view->load(url);
|
||||
m_webView->load(url);
|
||||
|
||||
QDataStream historyStream(history);
|
||||
historyStream >> *m_view->history();
|
||||
historyStream >> *m_webView->history();
|
||||
}
|
||||
|
||||
void WebTab::p_restoreTab(const WebTab::SavedTab &tab)
|
||||
|
@ -295,7 +304,7 @@ void WebTab::p_restoreTab(const WebTab::SavedTab &tab)
|
|||
QPixmap WebTab::renderTabPreview()
|
||||
{
|
||||
TabbedWebView* currentWebView = m_window->weView();
|
||||
WebPage* page = m_view->page();
|
||||
WebPage* page = m_webView->page();
|
||||
const QSize oldSize = page->viewportSize();
|
||||
const QPoint originalScrollPosition = page->mainFrame()->scrollPosition();
|
||||
|
||||
|
@ -319,7 +328,7 @@ QPixmap WebTab::renderTabPreview()
|
|||
|
||||
QPainter p(&pageImage);
|
||||
p.scale(scalingFactor, scalingFactor);
|
||||
m_view->page()->mainFrame()->render(&p, QWebFrame::ContentsLayer);
|
||||
m_webView->page()->mainFrame()->render(&p, QWebFrame::ContentsLayer);
|
||||
p.end();
|
||||
|
||||
page->setViewportSize(oldSize);
|
||||
|
@ -347,33 +356,24 @@ void WebTab::slotRestore()
|
|||
p_restoreTab(m_savedTab);
|
||||
m_savedTab.clear();
|
||||
|
||||
m_view->tabWidget()->getTabBar()->restoreTabTextColor(tabIndex());
|
||||
m_tabBar->restoreTabTextColor(tabIndex());
|
||||
}
|
||||
|
||||
void WebTab::enableUpdates()
|
||||
bool WebTab::isCurrentTab() const
|
||||
{
|
||||
setUpdatesEnabled(true);
|
||||
return tabIndex() == m_tabBar->currentIndex();
|
||||
}
|
||||
|
||||
int WebTab::tabIndex() const
|
||||
{
|
||||
return m_view->tabIndex();
|
||||
return m_webView->tabIndex();
|
||||
}
|
||||
|
||||
void WebTab::pinTab(int index)
|
||||
{
|
||||
TabWidget* tabWidget = m_window->tabWidget();
|
||||
if (!tabWidget) {
|
||||
return;
|
||||
}
|
||||
m_isPinned = !m_isPinned;
|
||||
|
||||
m_pinned = !m_pinned;
|
||||
index = tabWidget->pinUnPinTab(index, m_view->title());
|
||||
tabWidget->setTabText(index, m_view->title());
|
||||
tabWidget->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
WebTab::~WebTab()
|
||||
{
|
||||
delete m_locationBar.data();
|
||||
index = m_window->tabWidget()->pinUnPinTab(index, m_webView->title());
|
||||
m_tabBar->setTabText(index, m_webView->title());
|
||||
m_tabBar->setCurrentIndex(index);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#define WEBTAB_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
#include <QIcon>
|
||||
#include <QUrl>
|
||||
|
||||
|
@ -30,8 +29,9 @@ class QWebHistory;
|
|||
|
||||
class BrowserWindow;
|
||||
class LocationBar;
|
||||
class WebView;
|
||||
class TabbedWebView;
|
||||
class TabIcon;
|
||||
class TabBar;
|
||||
|
||||
class QUPZILLA_EXPORT WebTab : public QWidget
|
||||
{
|
||||
|
@ -46,18 +46,18 @@ public:
|
|||
SavedTab() { }
|
||||
SavedTab(WebTab* webTab);
|
||||
|
||||
bool isEmpty() const { return url.isEmpty(); }
|
||||
bool isEmpty() const;
|
||||
void clear();
|
||||
|
||||
friend QUPZILLA_EXPORT QDataStream &operator<<(QDataStream &stream, const SavedTab &tab);
|
||||
friend QUPZILLA_EXPORT QDataStream &operator>>(QDataStream &stream, SavedTab &tab);
|
||||
};
|
||||
|
||||
explicit WebTab(BrowserWindow* window, LocationBar* locationBar);
|
||||
~WebTab();
|
||||
explicit WebTab(BrowserWindow* window);
|
||||
|
||||
TabbedWebView* view() const;
|
||||
void setCurrentTab();
|
||||
TabbedWebView* webView() const;
|
||||
LocationBar* locationBar() const;
|
||||
TabIcon* tabIcon() const;
|
||||
|
||||
QUrl url() const;
|
||||
QString title() const;
|
||||
|
@ -65,31 +65,30 @@ public:
|
|||
QWebHistory* history() const;
|
||||
|
||||
void moveToWindow(BrowserWindow* window);
|
||||
void setTabbed(int index);
|
||||
void setTabTitle(const QString &title);
|
||||
|
||||
void setHistoryData(const QByteArray &data);
|
||||
QByteArray historyData() const;
|
||||
|
||||
void reload();
|
||||
void stop();
|
||||
void reload();
|
||||
bool isLoading() const;
|
||||
|
||||
bool isPinned() const;
|
||||
void pinTab(int index);
|
||||
void setPinned(bool state);
|
||||
|
||||
int tabIndex() const;
|
||||
void pinTab(int index);
|
||||
|
||||
void setLocationBar(LocationBar* bar);
|
||||
LocationBar* locationBar() const;
|
||||
bool isCurrentTab() const;
|
||||
void setCurrentTab();
|
||||
|
||||
bool inspectorVisible() const;
|
||||
void setInspectorVisible(bool v);
|
||||
|
||||
SavedTab savedTab() const;
|
||||
bool isRestored() const;
|
||||
|
||||
void restoreTab(const SavedTab &tab);
|
||||
|
||||
void p_restoreTab(const SavedTab &tab);
|
||||
void p_restoreTab(const QUrl &url, const QByteArray &history);
|
||||
|
||||
|
@ -98,18 +97,17 @@ public:
|
|||
private slots:
|
||||
void showNotification(QWidget* notif);
|
||||
void slotRestore();
|
||||
void enableUpdates();
|
||||
|
||||
private:
|
||||
BrowserWindow* m_window;
|
||||
TabbedWebView* m_view;
|
||||
TabbedWebView* m_webView;
|
||||
LocationBar* m_locationBar;
|
||||
TabIcon* m_tabIcon;
|
||||
TabBar* m_tabBar;
|
||||
QVBoxLayout* m_layout;
|
||||
QWidget* m_navigationContainer;
|
||||
QPointer<LocationBar> m_locationBar;
|
||||
|
||||
SavedTab m_savedTab;
|
||||
|
||||
bool m_pinned;
|
||||
bool m_isPinned;
|
||||
bool m_inspectorVisible;
|
||||
};
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ void GM_Plugin::init(InitState state, const QString &settingsPath)
|
|||
for (int i = 0; i < window->tabWidget()->count(); ++i) {
|
||||
WebTab* tab = qobject_cast<WebTab*>(window->tabWidget()->widget(i));
|
||||
if (tab) {
|
||||
webPageCreated(tab->view()->page());
|
||||
webPageCreated(tab->webView()->page());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user