1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Added option to detach tabs into own window.

Closes #441
This commit is contained in:
nowrep 2013-05-13 22:01:36 +02:00
parent d391b65bed
commit 09a1bec467
9 changed files with 84 additions and 8 deletions

View File

@ -2,6 +2,7 @@ Version 1.5.0
* development version * development version
* added support for Proxy Auto-Config (PAC) * added support for Proxy Auto-Config (PAC)
* added option to open another private window from private window * added option to open another private window from private window
* added option to detach tabs from window
* added delete action in edit context menu on page * added delete action in edit context menu on page
* added possibility to remove EasyList from AdBlock * added possibility to remove EasyList from AdBlock
* added inline domain completion to urlbar * added inline domain completion to urlbar

View File

@ -119,6 +119,7 @@ QupZilla::QupZilla(Qz::BrowserWindow type, QUrl startUrl)
, m_isStarting(false) , m_isStarting(false)
, m_startingUrl(startUrl) , m_startingUrl(startUrl)
, m_windowType(type) , m_windowType(type)
, m_startTab(0)
, m_menuBookmarksAction(0) , m_menuBookmarksAction(0)
, m_actionPrivateBrowsing(0) , m_actionPrivateBrowsing(0)
, m_sideBarManager(new SideBarManager(this)) , m_sideBarManager(new SideBarManager(this))
@ -152,6 +153,11 @@ QupZilla::QupZilla(Qz::BrowserWindow type, QUrl startUrl)
QTimer::singleShot(0, this, SLOT(postLaunch())); QTimer::singleShot(0, this, SLOT(postLaunch()));
} }
void QupZilla::openWithTab(WebTab* tab)
{
m_startTab = tab;
}
void QupZilla::postLaunch() void QupZilla::postLaunch()
{ {
#ifdef QZ_WS_X11 #ifdef QZ_WS_X11
@ -214,6 +220,11 @@ void QupZilla::postLaunch()
addTab = true; addTab = true;
} }
if (m_startTab) {
addTab = false;
m_tabWidget->addView(m_startTab);
}
if (addTab) { if (addTab) {
QNetworkRequest request(startUrl); QNetworkRequest request(startUrl);
request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1")); request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
@ -226,7 +237,7 @@ void QupZilla::postLaunch()
} }
if (m_tabWidget->getTabBar()->normalTabsCount() <= 0 && m_windowType != Qz::BW_OtherRestoredWindow) { if (m_tabWidget->getTabBar()->normalTabsCount() <= 0 && m_windowType != Qz::BW_OtherRestoredWindow) {
//Something went really wrong .. add one tab // Something went really wrong .. add one tab
QNetworkRequest request(m_homepage); QNetworkRequest request(m_homepage);
request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1")); request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
@ -236,7 +247,7 @@ void QupZilla::postLaunch()
aboutToHideEditMenu(); aboutToHideEditMenu();
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
// fill menus even if user don't call them // Fill menus even if user don't call them
if (m_windowType == Qz::BW_FirstAppWindow) { if (m_windowType == Qz::BW_FirstAppWindow) {
aboutToShowBookmarksMenu(); aboutToShowBookmarksMenu();
aboutToShowHistoryMostMenu(); aboutToShowHistoryMostMenu();

View File

@ -66,6 +66,8 @@ public:
explicit QupZilla(Qz::BrowserWindow type, QUrl startUrl = QUrl()); explicit QupZilla(Qz::BrowserWindow type, QUrl startUrl = QUrl());
~QupZilla(); ~QupZilla();
void openWithTab(WebTab* tab);
void loadSettings(); void loadSettings();
void saveSideBarWidth(); void saveSideBarWidth();
@ -268,6 +270,7 @@ private:
QUrl m_startingUrl; QUrl m_startingUrl;
QUrl m_homepage; QUrl m_homepage;
Qz::BrowserWindow m_windowType; Qz::BrowserWindow m_windowType;
WebTab* m_startTab;
QVBoxLayout* m_mainLayout; QVBoxLayout* m_mainLayout;
QSplitter* m_mainSplitter; QSplitter* m_mainSplitter;

View File

@ -134,6 +134,7 @@ void TabBar::contextMenuRequested(const QPoint &position)
if (!webTab) { if (!webTab) {
return; return;
} }
if (p_QupZilla->weView(m_clickedTab)->isLoading()) { if (p_QupZilla->weView(m_clickedTab)->isLoading()) {
menu.addAction(qIconProvider->standardIcon(QStyle::SP_BrowserStop), tr("&Stop Tab"), this, SLOT(stopTab())); menu.addAction(qIconProvider->standardIcon(QStyle::SP_BrowserStop), tr("&Stop Tab"), this, SLOT(stopTab()));
} }
@ -142,6 +143,11 @@ void TabBar::contextMenuRequested(const QPoint &position)
} }
menu.addAction(QIcon::fromTheme("tab-duplicate"), tr("&Duplicate Tab"), this, SLOT(duplicateTab())); menu.addAction(QIcon::fromTheme("tab-duplicate"), tr("&Duplicate Tab"), this, SLOT(duplicateTab()));
if (count() > 1 && !webTab->isPinned()) {
menu.addAction(QIcon::fromTheme("tab-detach"), tr("D&etach Tab"), this, SLOT(detachTab()));
}
menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab())); menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab()));
menu.addSeparator(); menu.addSeparator();
menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
@ -158,7 +164,7 @@ void TabBar::contextMenuRequested(const QPoint &position)
} }
else { else {
menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
menu.addAction(tr("Bookmark &All Ta&bs"), p_QupZilla, SLOT(bookmarkAllTabs())); menu.addAction(tr("Bookmark &All Tabs"), p_QupZilla, SLOT(bookmarkAllTabs()));
menu.addSeparator(); menu.addSeparator();
QAction* action = menu.addAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), m_tabWidget, SLOT(restoreClosedTab())); QAction* action = menu.addAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), m_tabWidget, SLOT(restoreClosedTab()));
action->setEnabled(m_tabWidget->canRestoreTab()); action->setEnabled(m_tabWidget->canRestoreTab());

View File

@ -57,6 +57,7 @@ signals:
void closeAllButCurrent(int index); void closeAllButCurrent(int index);
void closeTab(int index); void closeTab(int index);
void duplicateTab(int index); void duplicateTab(int index);
void detachTab(int index);
void moveAddTabButton(int posX); void moveAddTabButton(int posX);
@ -74,6 +75,7 @@ private slots:
void closeAllButCurrent() { emit closeAllButCurrent(m_clickedTab); } void closeAllButCurrent() { emit closeAllButCurrent(m_clickedTab); }
void closeTab() { emit closeTab(m_clickedTab); } void closeTab() { emit closeTab(m_clickedTab); }
void duplicateTab() { emit duplicateTab(m_clickedTab); } void duplicateTab() { emit duplicateTab(m_clickedTab); }
void detachTab() { emit detachTab(m_clickedTab); }
void bookmarkTab(); void bookmarkTab();
void pinTab(); void pinTab();

View File

@ -122,6 +122,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int))); connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
connect(m_tabBar, SIGNAL(closeAllButCurrent(int)), this, SLOT(closeAllButCurrent(int))); connect(m_tabBar, SIGNAL(closeAllButCurrent(int)), this, SLOT(closeAllButCurrent(int)));
connect(m_tabBar, SIGNAL(duplicateTab(int)), this, SLOT(duplicateTab(int))); connect(m_tabBar, SIGNAL(duplicateTab(int)), this, SLOT(duplicateTab(int)));
connect(m_tabBar, SIGNAL(detachTab(int)), this, SLOT(detachTab(int)));
connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(tabMoved(int,int))); connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(tabMoved(int,int)));
connect(m_tabBar, SIGNAL(moveAddTabButton(int)), this, SLOT(moveAddTabButton(int))); connect(m_tabBar, SIGNAL(moveAddTabButton(int)), this, SLOT(moveAddTabButton(int)));
@ -371,6 +372,22 @@ int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewT
return index; return index;
} }
int TabWidget::addView(WebTab* tab)
{
m_locationBars->addWidget(tab->locationBar());
tab->locationBar()->setWebView(tab->view());
int index = addTab(tab, QString());
setTabText(index, tab->title());
setTabIcon(index, tab->icon());
connect(tab->view(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
connect(tab->view(), SIGNAL(changed()), mApp, SLOT(setStateChanged()));
connect(tab->view(), SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString)));
return index;
}
void TabWidget::closeTab(int index, bool force) void TabWidget::closeTab(int index, bool force)
{ {
if (index == -1) { if (index == -1) {
@ -410,7 +427,7 @@ void TabWidget::closeTab(int index, bool force)
disconnect(webView, SIGNAL(changed()), mApp, SLOT(setStateChanged())); disconnect(webView, SIGNAL(changed()), mApp, SLOT(setStateChanged()));
disconnect(webView, SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString))); disconnect(webView, SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString)));
//Save last tab url and history // Save last tab url and history
m_closedTabsManager->saveView(webTab, index); m_closedTabsManager->saveView(webTab, index);
if (m_isClosingToLastTabIndex && m_lastTabIndex < count() && index == currentIndex()) { if (m_isClosingToLastTabIndex && m_lastTabIndex < count() && index == currentIndex()) {
@ -650,6 +667,28 @@ void TabWidget::closeAllButCurrent(int index)
} }
} }
void TabWidget::detachTab(int index)
{
WebTab* tab = weTab(index);
if (tab->isPinned() || count() == 1) {
return;
}
m_locationBars->removeWidget(tab->locationBar());
disconnect(tab->view(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
disconnect(tab->view(), SIGNAL(changed()), mApp, SLOT(setStateChanged()));
disconnect(tab->view(), SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString)));
QupZilla* window = mApp->makeNewWindow(Qz::BW_NewWindow);
tab->moveToWindow(window);
window->openWithTab(tab);
if (m_isClosingToLastTabIndex && m_lastTabIndex < count() && index == currentIndex()) {
setCurrentIndex(m_lastTabIndex);
}
}
int TabWidget::duplicateTab(int index) int TabWidget::duplicateTab(int index)
{ {
if (!validIndex(index)) { if (!validIndex(index)) {

View File

@ -106,6 +106,7 @@ public slots:
int addView(const QUrl &url, const QString &title = tr("New tab"), const Qz::NewTabPositionFlags &openFlags = Qz::NT_SelectedTab, bool selectLine = false, int position = -1); int addView(const QUrl &url, const QString &title = tr("New tab"), const Qz::NewTabPositionFlags &openFlags = Qz::NT_SelectedTab, bool selectLine = false, int position = -1);
int addView(QNetworkRequest req, const QString &title = tr("New tab"), const Qz::NewTabPositionFlags &openFlags = Qz::NT_SelectedTab, bool selectLine = false, int position = -1); int addView(QNetworkRequest req, const QString &title = tr("New tab"), const Qz::NewTabPositionFlags &openFlags = Qz::NT_SelectedTab, bool selectLine = false, int position = -1);
int addView(WebTab* tab);
int duplicateTab(int index); int duplicateTab(int index);
@ -114,6 +115,7 @@ public slots:
void reloadAllTabs(); void reloadAllTabs();
void stopTab(int index); void stopTab(int index);
void closeAllButCurrent(int index); void closeAllButCurrent(int index);
void detachTab(int index);
void restoreClosedTab(QObject* obj = 0); void restoreClosedTab(QObject* obj = 0);
void restoreAllClosedTabs(); void restoreAllClosedTabs();
void clearClosedTabsList(); void clearClosedTabsList();

View File

@ -180,8 +180,10 @@ void WebTab::moveToWindow(QupZilla* window)
{ {
p_QupZilla = window; p_QupZilla = window;
hideNavigationBar();
showNavigationBar(p_QupZilla->navigationContainer());
m_view->moveToWindow(p_QupZilla); m_view->moveToWindow(p_QupZilla);
//m_view->page()->moveToWindow(p_QupZilla);
} }
void WebTab::setHistoryData(const QByteArray &data) void WebTab::setHistoryData(const QByteArray &data)
@ -390,10 +392,10 @@ void WebTab::disconnectObjects()
disconnect(m_view); disconnect(m_view);
} }
WebTab::~WebTab()
void WebTab::hideNavigationBar()
{ {
// #838 !mApp->isClosing() fixes crash on app close with Oxygen theme if (m_navigationContainer && qzSettings->tabsOnTop) {
if (m_navigationContainer && qzSettings->tabsOnTop && !p_QupZilla->isClosing()) {
m_layout->removeWidget(m_navigationContainer); m_layout->removeWidget(m_navigationContainer);
// Needed to prevent flickering when closing tabs // Needed to prevent flickering when closing tabs
@ -403,6 +405,14 @@ WebTab::~WebTab()
// Needed to prevent deleting m_navigationContainer in ~QWidget // Needed to prevent deleting m_navigationContainer in ~QWidget
m_navigationContainer->setParent(p_QupZilla); m_navigationContainer->setParent(p_QupZilla);
} }
}
WebTab::~WebTab()
{
// #838 !p_QupZilla->isClosing() fixes crash on app close with Oxygen theme
if (!p_QupZilla->isClosing()) {
hideNavigationBar();
}
delete m_locationBar.data(); delete m_locationBar.data();
} }

View File

@ -103,6 +103,8 @@ private slots:
void slotRestore(); void slotRestore();
private: private:
void hideNavigationBar();
QupZilla* p_QupZilla; QupZilla* p_QupZilla;
TabbedWebView* m_view; TabbedWebView* m_view;
QVBoxLayout* m_layout; QVBoxLayout* m_layout;