diff --git a/bin/themes/chrome/linux.css b/bin/themes/chrome/linux.css index 9fa666ec4..f57218371 100644 --- a/bin/themes/chrome/linux.css +++ b/bin/themes/chrome/linux.css @@ -7,6 +7,5 @@ #tabbar::tab { - max-width: 250px; max-height: 26px; } diff --git a/bin/themes/chrome/main.css b/bin/themes/chrome/main.css index bf57b8cbe..fad9df431 100644 --- a/bin/themes/chrome/main.css +++ b/bin/themes/chrome/main.css @@ -98,9 +98,9 @@ } /*TabWidget*/ -#tabwidget::tab-bar +#tabbar::scroller { - right: 31px; + width: 0px; } #tabwidget-button-opentabs diff --git a/bin/themes/chrome/windows.css b/bin/themes/chrome/windows.css index 309ca4a29..ee1fc599c 100644 --- a/bin/themes/chrome/windows.css +++ b/bin/themes/chrome/windows.css @@ -9,7 +9,6 @@ #tabbar::tab { - max-width: 250px; height: 26px; } diff --git a/bin/themes/default/main.css b/bin/themes/default/main.css index 1af6cdfe7..000cca88b 100644 --- a/bin/themes/default/main.css +++ b/bin/themes/default/main.css @@ -98,7 +98,6 @@ /*TabWidget*/ #tabbar::tab { - max-width:250px; max-height: 28px; } @@ -108,9 +107,9 @@ qproperty-fixedsize: 20px 27px; } -#tabwidget::tab-bar +#tabbar::scroller { - right: 20px; + width: 0px; } #tabwidget-button-opentabs::menu-indicator diff --git a/bin/themes/linux/main.css b/bin/themes/linux/main.css index 4f9c306c4..c056dce7b 100644 --- a/bin/themes/linux/main.css +++ b/bin/themes/linux/main.css @@ -61,13 +61,12 @@ /*TabWidget*/ #tabbar::tab { - max-width:250px; max-height: 26px; } -#tabwidget::tab-bar +#tabbar::scroller { - right: 20px; + width: 0px; } #tabwidget-button-opentabs diff --git a/bin/themes/mac/linux.css b/bin/themes/mac/linux.css index 9fa666ec4..f57218371 100644 --- a/bin/themes/mac/linux.css +++ b/bin/themes/mac/linux.css @@ -7,6 +7,5 @@ #tabbar::tab { - max-width: 250px; max-height: 26px; } diff --git a/bin/themes/mac/main.css b/bin/themes/mac/main.css index eb9d386d4..7f1223384 100644 --- a/bin/themes/mac/main.css +++ b/bin/themes/mac/main.css @@ -93,9 +93,9 @@ } /*TabWidget*/ -#tabwidget::tab-bar +#tabbar::scroller { - right: 26px; + width: 0px; } #tabwidget-button-opentabs diff --git a/bin/themes/mac/windows.css b/bin/themes/mac/windows.css index 309ca4a29..ee1fc599c 100644 --- a/bin/themes/mac/windows.css +++ b/bin/themes/mac/windows.css @@ -9,7 +9,6 @@ #tabbar::tab { - max-width: 250px; height: 26px; } diff --git a/bin/themes/windows/linux.css b/bin/themes/windows/linux.css index 9fa666ec4..f57218371 100644 --- a/bin/themes/windows/linux.css +++ b/bin/themes/windows/linux.css @@ -7,6 +7,5 @@ #tabbar::tab { - max-width: 250px; max-height: 26px; } diff --git a/bin/themes/windows/main.css b/bin/themes/windows/main.css index 0f91d77cf..4a14ef6bb 100644 --- a/bin/themes/windows/main.css +++ b/bin/themes/windows/main.css @@ -103,9 +103,9 @@ } /*TabWidget*/ -#tabwidget::tab-bar +#tabbar::scroller { - right: 17px; + width: 0px; } #tabwidget-button-opentabs diff --git a/bin/themes/windows/windows.css b/bin/themes/windows/windows.css index 309ca4a29..ee1fc599c 100644 --- a/bin/themes/windows/windows.css +++ b/bin/themes/windows/windows.css @@ -9,7 +9,6 @@ #tabbar::tab { - max-width: 250px; height: 26px; } diff --git a/src/webview/tabbar.cpp b/src/webview/tabbar.cpp index 91454edec..f7d9f35d8 100644 --- a/src/webview/tabbar.cpp +++ b/src/webview/tabbar.cpp @@ -20,11 +20,22 @@ #include "qupzilla.h" #include "webtab.h" #include "iconprovider.h" +#include "toolbutton.h" -TabBar::TabBar(QupZilla* mainClass, QWidget* parent) : - QTabBar(parent) - ,p_QupZilla(mainClass) - ,m_clickedTab(0) +#define MAXIMUM_TAB_WIDTH 250 +#define MINIMUM_TAB_WIDTH 50 +#ifdef Q_WS_WIN +#define PINNED_TAB_WIDTH 38 +#else +#define PINNED_TAB_WIDTH 31 +#endif + +TabBar::TabBar(QupZilla* mainClass, QWidget* parent) + : QTabBar(parent) + , p_QupZilla(mainClass) + , m_tabWidget((TabWidget*)parentWidget()) + , m_clickedTab(0) + , m_pinnedTabsCount(0) { setObjectName("tabbar"); setContextMenuPolicy(Qt::CustomContextMenu); @@ -34,6 +45,8 @@ TabBar::TabBar(QupZilla* mainClass, QWidget* parent) : loadSettings(); connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &))); + connect(m_tabWidget, SIGNAL(pinnedTabClosed()), this, SLOT(pinnedTabClosed())); + connect(m_tabWidget, SIGNAL(pinnedTabAdded()), this, SLOT(pinnedTabAdded())); } void TabBar::loadSettings() @@ -53,15 +66,11 @@ void TabBar::contextMenuRequested(const QPoint &position) int index = tabAt(position); m_clickedTab = index; - TabWidget* tabWidget = qobject_cast(parentWidget()); - if (!tabWidget) - return; - QMenu menu; menu.addAction(QIcon(":/icons/menu/popup.png"),tr("&New tab"), p_QupZilla, SLOT(addTab())); menu.addSeparator(); if (index!=-1) { - WebTab* webTab = qobject_cast(tabWidget->widget(m_clickedTab)); + WebTab* webTab = qobject_cast(m_tabWidget->widget(m_clickedTab)); if (!webTab) return; if (p_QupZilla->weView(m_clickedTab)->isLoading()) @@ -72,23 +81,23 @@ void TabBar::contextMenuRequested(const QPoint &position) menu.addAction(tr("&Duplicate Tab"), this, SLOT(duplicateTab())); menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab())); menu.addSeparator(); - menu.addAction(tr("Re&load All Tabs"), tabWidget, SLOT(reloadAllTabs())); + menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab())); menu.addAction(tr("Bookmark &All Tabs"), p_QupZilla, SLOT(bookmarkAllTabs())); menu.addSeparator(); QAction* action = p_QupZilla->actionRestoreTab(); - tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false); + m_tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false); menu.addAction(action); menu.addSeparator(); menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent())); menu.addAction(QIcon::fromTheme("window-close"),tr("Cl&ose"), this, SLOT(closeTab())); menu.addSeparator(); } else { - menu.addAction(tr("Reloa&d All Tabs"), 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.addSeparator(); - QAction* action = menu.addAction(QIcon::fromTheme("user-trash"),tr("Restore &Closed Tab"), tabWidget, SLOT(restoreClosedTab())); - tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false); + QAction* action = menu.addAction(QIcon::fromTheme("user-trash"),tr("Restore &Closed Tab"), m_tabWidget, SLOT(restoreClosedTab())); + m_tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false); } //Prevent choosing first option with double rightclick @@ -101,15 +110,25 @@ void TabBar::contextMenuRequested(const QPoint &position) QSize TabBar::tabSizeHint(int index) const { QSize size = QTabBar::tabSizeHint(index); - TabWidget* tabWidget = qobject_cast(parentWidget()); - if (tabWidget) { - WebTab* webTab = qobject_cast(tabWidget->widget(index)); - if (webTab && webTab->isPinned()) -#ifdef Q_WS_WIN - size.setWidth(38); -#else - size.setWidth(31); -#endif + WebTab* webTab = qobject_cast(m_tabWidget->widget(index)); + + if (webTab && webTab->isPinned()) { + size.setWidth(PINNED_TAB_WIDTH); + } else { + int availableWidth = width() - (PINNED_TAB_WIDTH * m_pinnedTabsCount) - m_tabWidget->buttonListTabs()->width(); + int normalTabsCount = count() - m_pinnedTabsCount; + if (availableWidth >= MAXIMUM_TAB_WIDTH * normalTabsCount) + size.setWidth(MAXIMUM_TAB_WIDTH); + else if (availableWidth < MINIMUM_TAB_WIDTH * normalTabsCount) + size.setWidth(MINIMUM_TAB_WIDTH); + else { + int maxWidthForTab = availableWidth / normalTabsCount; + //Fill any empty space (gotten from rounding) with last tab + if (index == count() - 1) + size.setWidth( (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab); + else + size.setWidth(maxWidthForTab); + } } return size; } @@ -131,11 +150,8 @@ void TabBar::tabInserted(int index) void TabBar::showCloseButton(int index) { - TabWidget* tabWidget = qobject_cast(parentWidget()); - if (!tabWidget) - return; - WebTab* webTab = qobject_cast(tabWidget->widget(index)); + WebTab* webTab = qobject_cast(m_tabWidget->widget(index)); if (webTab && webTab->isPinned()) return; @@ -161,11 +177,7 @@ void TabBar::updateCloseButton(int index) if (!button) return; - TabWidget* tabWidget = qobject_cast(parentWidget()); - if (!tabWidget) - return; - - WebTab* webTab = qobject_cast(tabWidget->widget(index)); + WebTab* webTab = qobject_cast(m_tabWidget->widget(index)); if (webTab && webTab->isPinned()) button->hide(); else @@ -175,10 +187,10 @@ void TabBar::updateCloseButton(int index) void TabBar::closeCurrentTab() { int id = currentIndex(); - TabWidget* tabWidget = qobject_cast(parentWidget()); - if (!tabWidget || id < 0) + if (id < 0) return; - tabWidget->closeTab(id); + + m_tabWidget->closeTab(id); } void TabBar::bookmarkTab() @@ -188,24 +200,32 @@ void TabBar::bookmarkTab() void TabBar::pinTab() { - TabWidget* tabWidget = qobject_cast(parentWidget()); - if (!tabWidget) - return; - - WebTab* webTab = qobject_cast(tabWidget->widget(m_clickedTab)); + WebTab* webTab = qobject_cast(m_tabWidget->widget(m_clickedTab)); if (!webTab) return; webTab->pinTab(m_clickedTab); + + if (webTab->isPinned()) + m_pinnedTabsCount++; + else + m_pinnedTabsCount--; +} + +void TabBar::pinnedTabClosed() +{ + m_pinnedTabsCount--; +} + +void TabBar::pinnedTabAdded() +{ + m_pinnedTabsCount++; } void TabBar::mouseDoubleClickEvent(QMouseEvent* event) { - TabWidget* tabWidget = qobject_cast(parentWidget()); - if (!tabWidget) - return; if (event->button() == Qt::LeftButton && tabAt(event->pos()) == -1) { - tabWidget->addView(QUrl(),tr("New tab"), TabWidget::NewTab, true); + m_tabWidget->addView(QUrl(),tr("New tab"), TabWidget::NewTab, true); return; } QTabBar::mouseDoubleClickEvent(event); diff --git a/src/webview/tabbar.h b/src/webview/tabbar.h index 02983307f..a13540ed5 100644 --- a/src/webview/tabbar.h +++ b/src/webview/tabbar.h @@ -27,6 +27,7 @@ #include class QupZilla; +class TabWidget; class TabBar : public QTabBar { Q_OBJECT @@ -52,6 +53,9 @@ signals: public slots: private slots: + void pinnedTabAdded(); + void pinnedTabClosed(); + void contextMenuRequested(const QPoint &position); void reloadTab() { emit reloadTab(m_clickedTab); } void stopTab() { emit stopTab(m_clickedTab); } @@ -70,9 +74,13 @@ private: // void tabInserted(int index); QupZilla* p_QupZilla; + TabWidget* m_tabWidget; + bool m_showCloseButtonWithOneTab; bool m_showTabBarWithOneTab; + int m_clickedTab; + int m_pinnedTabsCount; }; diff --git a/src/webview/tabwidget.cpp b/src/webview/tabwidget.cpp index 1575cb495..f74289aa0 100644 --- a/src/webview/tabwidget.cpp +++ b/src/webview/tabwidget.cpp @@ -106,7 +106,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) : , m_locationBars(new QStackedWidget()) { setObjectName("tabwidget"); - m_tabBar = new TabBar(p_QupZilla); + m_tabBar = new TabBar(p_QupZilla, this); setTabBar(m_tabBar); connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int))); @@ -140,7 +140,7 @@ void TabWidget::loadSettings() { QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); settings.beginGroup("Browser-Tabs-Settings"); - m_hideCloseButtonWithOneTab = settings.value("hideCloseButtonWithOneTab",false).toBool(); + m_hideCloseButtonWithOneTab = settings.value("hideCloseButtonWithOneTab", false).toBool(); m_hideTabBarWithOneTab = settings.value("hideTabsWithOneTab",false).toBool(); settings.endGroup(); settings.beginGroup("Web-URL-Settings"); @@ -259,7 +259,7 @@ int TabWidget::addView(QUrl url, const QString &title, OpenUrlIn openIn, bool se void TabWidget::setTabText(int index, const QString& text) { - QString newtext = text + " "; + QString newtext = text; if (WebTab* webTab = qobject_cast(p_QupZilla->tabWidget()->widget(index)) ) { if (webTab->isPinned()) @@ -279,9 +279,10 @@ void TabWidget::closeTab(int index) if (!webView) return; + if (webView->webTab()->isPinned()) + emit pinnedTabClosed(); + m_locationBars->removeWidget(webView->webTab()->locationBar()); -// disconnect(weView(index), SIGNAL(siteIconChanged()), p_QupZilla->locationBar(), SLOT(siteIconChanged())); -// disconnect(weView(index), SIGNAL(showUrl(QUrl)), p_QupZilla->locationBar(), SLOT(showUrl(QUrl))); disconnect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); disconnect(webView, SIGNAL(changed()), mApp, SLOT(setStateChanged())); disconnect(webView, SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString))); @@ -497,8 +498,10 @@ void TabWidget::restorePinnedTabs() addedIndex = addView(url); } WebTab* webTab = (WebTab*)widget(addedIndex); - if (webTab) + if (webTab) { webTab->setPinned(true); + emit pinnedTabAdded(); + } m_tabBar->moveTab(addedIndex, i); m_tabBar->updateCloseButton(i); diff --git a/src/webview/tabwidget.h b/src/webview/tabwidget.h index fb6b497b3..a00927bcf 100644 --- a/src/webview/tabwidget.h +++ b/src/webview/tabwidget.h @@ -59,6 +59,9 @@ public: QStackedWidget* locationBars() { return m_locationBars; } ToolButton* buttonListTabs() { return m_buttonListTabs; } +signals: + void pinnedTabClosed(); + void pinnedTabAdded(); public slots: void closeTab(int index=-1); diff --git a/src/webview/webinspectordockwidget.cpp b/src/webview/webinspectordockwidget.cpp index 0801e96a5..de8992b40 100644 --- a/src/webview/webinspectordockwidget.cpp +++ b/src/webview/webinspectordockwidget.cpp @@ -6,7 +6,7 @@ #include "qupzilla.h" WebInspectorDockWidget::WebInspectorDockWidget(QupZilla* mainClass) - : QDockWidget() + : QDockWidget(mainClass) , p_QupZilla(mainClass) , m_inspector(0) {