From 83f3c90752590594132e46083af09e0a81bb6bba Mon Sep 17 00:00:00 2001 From: nowrep Date: Sat, 9 Feb 2013 13:00:45 +0100 Subject: [PATCH] Added option to show tabs on top. You can change it in Menu View -> Toolbars Closes #640 --- CHANGELOG | 2 + src/lib/app/qupzilla.cpp | 65 +++++++++++++++++++++++-------- src/lib/app/qupzilla.h | 35 ++++++++++------- src/lib/lib.pro | 2 +- src/lib/other/macmenureceiver.cpp | 6 ++- src/lib/other/macmenureceiver.h | 1 + src/lib/other/qzsettings.cpp | 5 ++- src/lib/other/qzsettings.h | 1 + src/lib/webview/tabbar.cpp | 5 ++- src/lib/webview/tabwidget.cpp | 41 +++++++++++++++++-- src/lib/webview/tabwidget.h | 18 +++++---- src/lib/webview/webtab.cpp | 31 ++++++++++++++- src/lib/webview/webtab.h | 4 +- translations/empty.ts | 4 ++ 14 files changed, 171 insertions(+), 49 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b967b4839..f65988948 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ Version 1.4.0 * QtWebKit 2.3 new features - caret browsing, animated scrolling * added support for FTP listing files and downloading * added support for saving passwords of multiple users per site + * added support for showing tabs on top * asking user whether to allow site to use notifications/geolocation * option to set JavaScript privacy permissions * option to specify default search engine used in locationbar @@ -28,6 +29,7 @@ Version 1.4.0 * X11: fixed Ctrl+Q shortcut for DEs other than KDE and Gnome * windows: improved installer allows registering as default web browser * windows: check and set as default browser from preferences + * mac: fixed not working global menu after closing browser window Version 1.3.5 * released 16 September 2012 diff --git a/src/lib/app/qupzilla.cpp b/src/lib/app/qupzilla.cpp index c4aa7e339..808a6fb0e 100644 --- a/src/lib/app/qupzilla.cpp +++ b/src/lib/app/qupzilla.cpp @@ -60,6 +60,7 @@ #include "reloadstopbutton.h" #include "enhancedmenu.h" #include "settings.h" +#include "qzsettings.h" #include "webtab.h" #include "speeddial.h" #include "qtwin.h" @@ -289,9 +290,16 @@ void QupZilla::setupUi() m_navigationBar->setSplitterSizes(locationBarWidth, websearchBarWidth); m_bookmarksToolbar = new BookmarksToolbar(this); + m_navigationContainer = new QWidget(this); + QVBoxLayout* l = new QVBoxLayout(m_navigationContainer); + l->setContentsMargins(0, 0, 0, 0); + l->setSpacing(0); + l->addWidget(m_navigationBar); + l->addWidget(m_bookmarksToolbar); + m_navigationContainer->setLayout(l); + m_mainSplitter->addWidget(m_tabWidget); - m_mainLayout->addWidget(m_navigationBar); - m_mainLayout->addWidget(m_bookmarksToolbar); + m_mainLayout->addWidget(m_navigationContainer); m_mainLayout->addWidget(m_mainSplitter); m_mainSplitter->setCollapsible(0, false); @@ -415,6 +423,9 @@ void QupZilla::setupMenu() #else m_menuEncoding = new QMenu(0); #endif + m_actionTabsOnTop = new QAction(tr("&Tabs on Top"), MENU_RECEIVER); + m_actionTabsOnTop->setCheckable(true); + connect(m_actionTabsOnTop, SIGNAL(triggered(bool)), this, SLOT(triggerTabsOnTop(bool))); m_actionShowFullScreen = new QAction(tr("&Fullscreen"), MENU_RECEIVER); m_actionShowFullScreen->setCheckable(true); m_actionShowFullScreen->setShortcut(QKeySequence("F11")); @@ -444,6 +455,8 @@ void QupZilla::setupMenu() #endif toolbarsMenu->addAction(m_actionShowToolbar); toolbarsMenu->addAction(m_actionShowBookmarksToolbar); + toolbarsMenu->addSeparator(); + toolbarsMenu->addAction(m_actionTabsOnTop); QMenu* sidebarsMenu = new QMenu(tr("Sidebars")); m_sideBarManager->setSideBarMenu(sidebarsMenu); @@ -791,6 +804,15 @@ LocationBar* QupZilla::locationBar() const return qobject_cast(m_tabWidget->locationBars()->currentWidget()); } +QWidget* QupZilla::navigationContainer() +{ + if (!qzSettings->tabsOnTop) { + return 0; + } + + return m_navigationContainer; +} + void QupZilla::setWindowTitle(const QString &t) { QString title = t; @@ -1066,6 +1088,7 @@ void QupZilla::aboutToShowViewMenu() m_actionShowStatusbar->setChecked(statusBar()->isVisible()); m_actionShowBookmarksToolbar->setChecked(m_bookmarksToolbar->isVisible()); + m_actionTabsOnTop->setChecked(qzSettings->tabsOnTop); m_actionPageSource->setEnabled(true); @@ -1307,7 +1330,7 @@ void QupZilla::reloadByPassCache() weView()->triggerPageAction(QWebPage::ReloadAndBypassCache); } -void QupZilla::loadActionUrl(QObject *obj) +void QupZilla::loadActionUrl(QObject* obj) { if (!obj) { obj = sender(); @@ -1526,6 +1549,18 @@ void QupZilla::showBookmarkImport() b->show(); } +void QupZilla::triggerTabsOnTop(bool enable) +{ + if (enable) { + m_tabWidget->showNavigationBar(m_navigationContainer); + } + else { + m_mainLayout->insertWidget(0, m_navigationContainer); + } + + qzSettings->tabsOnTop = enable; +} + void QupZilla::refreshHistory() { m_navigationBar->refreshHistory(); @@ -1610,10 +1645,11 @@ void QupZilla::webSearch() void QupZilla::searchOnPage() { SearchToolBar* toolBar = searchToolBar(); + const int searchPos = qzSettings->tabsOnTop ? 1 : 2; if (!toolBar) { toolBar = new SearchToolBar(weView(), this); - m_mainLayout->insertWidget(3, toolBar); + m_mainLayout->insertWidget(searchPos, toolBar); } toolBar->focusSearchLine(); @@ -1995,9 +2031,10 @@ void QupZilla::closeEvent(QCloseEvent* event) SearchToolBar* QupZilla::searchToolBar() { SearchToolBar* toolBar = 0; + const int searchPos = qzSettings->tabsOnTop ? 1 : 2; - if (m_mainLayout->count() == 4) { - toolBar = qobject_cast(m_mainLayout->itemAt(3)->widget()); + if (m_mainLayout->count() == searchPos + 1) { + toolBar = qobject_cast(m_mainLayout->itemAt(searchPos)->widget()); } return toolBar; @@ -2242,11 +2279,9 @@ bool QupZilla::nativeEvent(const QByteArray &eventType, void* _message, long* re m_sideBar.data()->installEventFilter(this); } - if (m_mainLayout->count() == 4) { - SearchToolBar* search = qobject_cast(m_mainLayout->itemAt(3)->widget()); - if (search) { - search->installEventFilter(this); - } + SearchToolBar* search = searchToolBar(); + if (search) { + search->installEventFilter(this); } if (m_webInspectorDock) { @@ -2291,11 +2326,9 @@ void QupZilla::applyBlurToMainWindow(bool force) topMargin += m_bookmarksToolbar->isVisible() ? m_bookmarksToolbar->height() : 0; topMargin += m_tabWidget->getTabBar()->height(); - if (m_mainLayout->count() == 4) { - SearchToolBar* search = qobject_cast(m_mainLayout->itemAt(3)->widget()); - if (search) { - bottomMargin += search->height(); - } + SearchToolBar* search = searchToolBar(); + if (search) { + bottomMargin += search->height(); } bottomMargin += statusBar()->isVisible() ? statusBar()->height() : 0; diff --git a/src/lib/app/qupzilla.h b/src/lib/app/qupzilla.h index d26624b0e..2d9818f48 100644 --- a/src/lib/app/qupzilla.h +++ b/src/lib/app/qupzilla.h @@ -87,21 +87,23 @@ public: TabbedWebView* weView(int index) const; LocationBar* locationBar() const; - inline TabWidget* tabWidget() { return m_tabWidget; } - inline BookmarksToolbar* bookmarksToolbar() { return m_bookmarksToolbar; } - inline StatusBarMessage* statusBarMessage() { return m_statusBarMessage; } - inline NavigationBar* navigationBar() { return m_navigationBar; } - inline SideBarManager* sideBarManager() { return m_sideBarManager; } - inline ProgressBar* progressBar() { return m_progressBar; } - inline QLabel* ipLabel() { return m_ipLabel; } - inline AdBlockIcon* adBlockIcon() { return m_adblockIcon; } - inline QMenu* menuHelp() { return m_menuHelp; } - inline QAction* actionRestoreTab() { return m_actionRestoreTab; } - inline QAction* actionReload() { return m_actionReload; } - inline QMenu* superMenu() { return m_superMenu; } + TabWidget* tabWidget() { return m_tabWidget; } + BookmarksToolbar* bookmarksToolbar() { return m_bookmarksToolbar; } + StatusBarMessage* statusBarMessage() { return m_statusBarMessage; } + NavigationBar* navigationBar() { return m_navigationBar; } + SideBarManager* sideBarManager() { return m_sideBarManager; } + ProgressBar* progressBar() { return m_progressBar; } + QLabel* ipLabel() { return m_ipLabel; } + AdBlockIcon* adBlockIcon() { return m_adblockIcon; } + QMenu* menuHelp() { return m_menuHelp; } + QAction* actionRestoreTab() { return m_actionRestoreTab; } + QAction* actionReload() { return m_actionReload; } + QMenu* superMenu() { return m_superMenu; } - inline bool isClosing() { return m_isClosing; } - inline QUrl homepageUrl() { return m_homepage; } + QWidget* navigationContainer(); + + bool isClosing() { return m_isClosing; } + QUrl homepageUrl() { return m_homepage; } signals: void startingCompleted(); @@ -189,9 +191,10 @@ private slots: void zoomOut(); void zoomReset(); void fullScreen(bool make); - void changeEncoding(QObject *obj = 0); + void changeEncoding(QObject* obj = 0); void triggerCaretBrowsing(); + void triggerTabsOnTop(bool enable); void closeWindow(); bool quitApp(); @@ -275,6 +278,7 @@ private: #ifndef Q_OS_MAC QAction* m_actionShowMenubar; #endif + QAction* m_actionTabsOnTop; QAction* m_actionShowFullScreen; QAction* m_actionShowBookmarksSideBar; QAction* m_actionShowHistorySideBar; @@ -291,6 +295,7 @@ private: AdBlockIcon* m_adblockIcon; QPointer m_webInspectorDock; + QWidget* m_navigationContainer; BookmarksToolbar* m_bookmarksToolbar; TabWidget* m_tabWidget; QPointer m_sideBar; diff --git a/src/lib/lib.pro b/src/lib/lib.pro index c74430612..e89385096 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -446,7 +446,7 @@ win32 { SOURCES += other/registerqappassociation.cpp } -macx { +mac { HEADERS += other/macmenureceiver.h SOURCES += other/macmenureceiver.cpp } diff --git a/src/lib/other/macmenureceiver.cpp b/src/lib/other/macmenureceiver.cpp index 77f9131e8..f2abf26b4 100644 --- a/src/lib/other/macmenureceiver.cpp +++ b/src/lib/other/macmenureceiver.cpp @@ -313,12 +313,15 @@ void MacMenuReceiver::changeEncoding(QObject* obj) callSlot("changeEncoding", false, Q_ARG(QObject*, obj)); } - void MacMenuReceiver::triggerCaretBrowsing() { callSlot("triggerCaretBrowsing"); } +void MacMenuReceiver::triggerTabsOnTop(bool enable) +{ + callSlot("triggerTabsOnTop", false, Q_ARG(bool, enable)); +} void MacMenuReceiver::closeWindow() { @@ -330,7 +333,6 @@ void MacMenuReceiver::quitApp() if (!callSlot("quitApp")) { mApp->quitApplication(); } - } void MacMenuReceiver::printPage(QWebFrame* frame) diff --git a/src/lib/other/macmenureceiver.h b/src/lib/other/macmenureceiver.h index 642d96351..8f7e02dea 100644 --- a/src/lib/other/macmenureceiver.h +++ b/src/lib/other/macmenureceiver.h @@ -120,6 +120,7 @@ private slots: void changeEncoding(QObject* obj = 0); void triggerCaretBrowsing(); + void triggerTabsOnTop(bool enable); void closeWindow(); void quitApp(); diff --git a/src/lib/other/qzsettings.cpp b/src/lib/other/qzsettings.cpp index 1199df113..0146fecbc 100644 --- a/src/lib/other/qzsettings.cpp +++ b/src/lib/other/qzsettings.cpp @@ -55,6 +55,7 @@ void QzSettings::loadSettings() settings.beginGroup("Browser-Tabs-Settings"); newTabPosition = settings.value("OpenNewTabsSelected", false).toBool() ? Qz::NT_SelectedTab : Qz::NT_NotSelectedTab; + tabsOnTop = settings.value("TabsOnTop", true).toBool(); settings.endGroup(); } @@ -62,10 +63,12 @@ void QzSettings::saveSettings() { Settings settings; settings.beginGroup("Web-Browser-Settings"); - settings.setValue("AutomaticallyOpenProtocols", autoOpenProtocols); settings.setValue("BlockOpeningProtocols", blockedProtocols); + settings.endGroup(); + settings.beginGroup("Browser-Tabs-Settings"); + settings.setValue("TabsOnTop", tabsOnTop); settings.endGroup(); } diff --git a/src/lib/other/qzsettings.h b/src/lib/other/qzsettings.h index 8b41bfb2f..0061b4334 100644 --- a/src/lib/other/qzsettings.h +++ b/src/lib/other/qzsettings.h @@ -58,6 +58,7 @@ public: // Browser-Tabs-Settings Qz::NewTabPositionFlag newTabPosition; + bool tabsOnTop; }; #define qzSettings Settings::staticSettings() diff --git a/src/lib/webview/tabbar.cpp b/src/lib/webview/tabbar.cpp index 463eee919..f25fd048e 100644 --- a/src/lib/webview/tabbar.cpp +++ b/src/lib/webview/tabbar.cpp @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2012 David Rosca +* Copyright (C) 2010-2013 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -399,6 +399,8 @@ void TabBar::currentTabChanged(int index) showCloseButton(index); hideCloseButton(m_tabWidget->lastTabIndex()); + + m_tabWidget->currentTabChanged(index); } void TabBar::bookmarkTab() @@ -482,6 +484,7 @@ void TabBar::tabRemoved(int index) { Q_UNUSED(index) + m_tabWidget->showNavigationBar(p_QupZilla->navigationContainer()); showCloseButton(currentIndex()); } diff --git a/src/lib/webview/tabwidget.cpp b/src/lib/webview/tabwidget.cpp index 3feba84d9..70586e778 100644 --- a/src/lib/webview/tabwidget.cpp +++ b/src/lib/webview/tabwidget.cpp @@ -30,6 +30,7 @@ #include "locationbar.h" #include "websearchbar.h" #include "settings.h" +#include "qzsettings.h" #include #include @@ -111,7 +112,6 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) m_tabBar = new TabBar(p_QupZilla, this); setTabBar(m_tabBar); - connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int))); connect(this, SIGNAL(currentChanged(int)), p_QupZilla, SLOT(refreshHistory())); connect(m_tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); @@ -429,12 +429,13 @@ void TabWidget::currentTabChanged(int index) WebTab* webTab = weTab(index); LocationBar* locBar = webTab->locationBar(); - if (m_locationBars->indexOf(locBar) != -1) { + if (locBar && m_locationBars->indexOf(locBar) != -1) { m_locationBars->setCurrentWidget(locBar); } webTab->setCurrentTab(); p_QupZilla->currentTabChanged(); + showNavigationBar(p_QupZilla->navigationContainer()); } void TabWidget::tabMoved(int before, int after) @@ -586,6 +587,25 @@ int TabWidget::lastTabIndex() const return m_lastTabIndex; } +void TabWidget::showNavigationBar(QWidget* bar) +{ + WebTab* tab = weTab(); + + if (tab) { + tab->showNavigationBar(bar); + } +} + +TabBar* TabWidget::getTabBar() const +{ + return m_tabBar; +} + +ClosedTabsManager* TabWidget::closedTabsManager() const +{ + return m_closedTabsManager; +} + void TabWidget::reloadAllTabs() { for (int i = 0; i < count(); i++) { @@ -687,11 +707,26 @@ void TabWidget::clearClosedTabsList() m_closedTabsManager->clearList(); } -bool TabWidget::canRestoreTab() +bool TabWidget::canRestoreTab() const { return m_closedTabsManager->isClosedTabAvailable(); } +QStackedWidget* TabWidget::locationBars() const +{ + return m_locationBars; +} + +ToolButton* TabWidget::buttonListTabs() const +{ + return m_buttonListTabs; +} + +AddTabButton* TabWidget::buttonAddTab() const +{ + return m_buttonAddTab; +} + void TabWidget::aboutToShowClosedTabsMenu() { if (!m_closedInsteadOpened) { diff --git a/src/lib/webview/tabwidget.h b/src/lib/webview/tabwidget.h index 83301e54c..2c6dfc33c 100644 --- a/src/lib/webview/tabwidget.h +++ b/src/lib/webview/tabwidget.h @@ -75,6 +75,7 @@ public: void nextTab(); void previousTab(); + void currentTabChanged(int index); int normalTabsCount() const; int pinnedTabsCount() const; @@ -82,13 +83,16 @@ public: void showTabBar(); int lastTabIndex() const; - TabBar* getTabBar() { return m_tabBar; } - ClosedTabsManager* closedTabsManager() { return m_closedTabsManager; } - bool canRestoreTab(); + void showNavigationBar(QWidget* bar); + + TabBar* getTabBar() const; + ClosedTabsManager* closedTabsManager() const; QList allTabs(bool withPinned = true); - QStackedWidget* locationBars() { return m_locationBars; } - ToolButton* buttonListTabs() { return m_buttonListTabs; } - AddTabButton* buttonAddTab() { return m_buttonAddTab; } + bool canRestoreTab() const; + + QStackedWidget* locationBars() const; + ToolButton* buttonListTabs() const; + AddTabButton* buttonAddTab() const; void disconnectObjects(); @@ -122,7 +126,6 @@ public slots: private slots: void aboutToShowTabsMenu(); void actionChangeIndex(); - void currentTabChanged(int index); void tabMoved(int before, int after); private: @@ -142,6 +145,7 @@ private: bool m_newTabAfterActive; bool m_newEmptyTabAfterActive; QUrl m_urlOnNewTab; + QupZilla* p_QupZilla; int m_lastTabIndex; diff --git a/src/lib/webview/webtab.cpp b/src/lib/webview/webtab.cpp index ab4ddd29e..5e784826e 100644 --- a/src/lib/webview/webtab.cpp +++ b/src/lib/webview/webtab.cpp @@ -70,6 +70,7 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab) WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar) : QWidget() , p_QupZilla(mainClass) + , m_navigationContainer(0) , m_locationBar(locationBar) , m_pinned(false) , m_inspectorVisible(false) @@ -84,6 +85,7 @@ WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar) m_layout->setSpacing(0); m_view = new TabbedWebView(p_QupZilla, this); + m_view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); WebPage* page = new WebPage(p_QupZilla); m_view->setWebPage(page); m_layout->addWidget(m_view); @@ -293,11 +295,13 @@ QPixmap WebTab::renderTabPreview() void WebTab::showNotification(QWidget* notif) { - if (m_layout->count() > 1) { + const int notifPos = m_navigationContainer ? 2 : 1; + + if (m_layout->count() > notifPos) { delete m_layout->itemAt(0)->widget(); } - m_layout->insertWidget(0, notif); + m_layout->insertWidget(notifPos - 1, notif); notif->show(); } @@ -306,6 +310,18 @@ int WebTab::tabIndex() const return m_view->tabIndex(); } +void WebTab::showNavigationBar(QWidget* bar) +{ + if (bar) { + m_navigationContainer = bar; + m_layout->insertWidget(0, m_navigationContainer); + + // Needed to prevent flickering when closing tabs + m_navigationContainer->setUpdatesEnabled(true); + m_navigationContainer->show(); + } +} + void WebTab::pinTab(int index) { TabWidget* tabWidget = p_QupZilla->tabWidget(); @@ -337,5 +353,16 @@ void WebTab::disconnectObjects() WebTab::~WebTab() { + if (m_navigationContainer) { + m_layout->removeWidget(m_navigationContainer); + + // Needed to prevent flickering when closing tabs + m_navigationContainer->setUpdatesEnabled(false); + m_navigationContainer->hide(); + + // Needed to prevent deleting m_navigationContainer in ~QWidget + m_navigationContainer->setParent(p_QupZilla); + } + delete m_locationBar.data(); } diff --git a/src/lib/webview/webtab.h b/src/lib/webview/webtab.h index 15e50f345..696f5e240 100644 --- a/src/lib/webview/webtab.h +++ b/src/lib/webview/webtab.h @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2012 David Rosca +* Copyright (C) 2010-2013 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -76,6 +76,7 @@ public: void setPinned(bool state); int tabIndex() const; + void showNavigationBar(QWidget* bar); void setLocationBar(LocationBar* bar); LocationBar* locationBar() const; @@ -102,6 +103,7 @@ private: QupZilla* p_QupZilla; TabbedWebView* m_view; QVBoxLayout* m_layout; + QWidget* m_navigationContainer; QPointer m_locationBar; SavedTab m_savedTab; diff --git a/translations/empty.ts b/translations/empty.ts index 717b6762c..08d4db968 100644 --- a/translations/empty.ts +++ b/translations/empty.ts @@ -3229,6 +3229,10 @@ Are you sure to quit QupZilla? Enable &Caret Browsing + + &Tabs on Top + + QupZillaSchemeReply