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

Updated drawing of tabs in TabBar. It will no longer show "..." when not

needed.
With this update is also possible implement showing "new tab" button
after the last tab
This commit is contained in:
nowrep 2011-10-14 23:12:10 +02:00
parent edbcb5e541
commit d361c0631d
16 changed files with 95 additions and 69 deletions

View File

@ -7,6 +7,5 @@
#tabbar::tab #tabbar::tab
{ {
max-width: 250px;
max-height: 26px; max-height: 26px;
} }

View File

@ -98,9 +98,9 @@
} }
/*TabWidget*/ /*TabWidget*/
#tabwidget::tab-bar #tabbar::scroller
{ {
right: 31px; width: 0px;
} }
#tabwidget-button-opentabs #tabwidget-button-opentabs

View File

@ -9,7 +9,6 @@
#tabbar::tab #tabbar::tab
{ {
max-width: 250px;
height: 26px; height: 26px;
} }

View File

@ -98,7 +98,6 @@
/*TabWidget*/ /*TabWidget*/
#tabbar::tab #tabbar::tab
{ {
max-width:250px;
max-height: 28px; max-height: 28px;
} }
@ -108,9 +107,9 @@
qproperty-fixedsize: 20px 27px; qproperty-fixedsize: 20px 27px;
} }
#tabwidget::tab-bar #tabbar::scroller
{ {
right: 20px; width: 0px;
} }
#tabwidget-button-opentabs::menu-indicator #tabwidget-button-opentabs::menu-indicator

View File

@ -61,13 +61,12 @@
/*TabWidget*/ /*TabWidget*/
#tabbar::tab #tabbar::tab
{ {
max-width:250px;
max-height: 26px; max-height: 26px;
} }
#tabwidget::tab-bar #tabbar::scroller
{ {
right: 20px; width: 0px;
} }
#tabwidget-button-opentabs #tabwidget-button-opentabs

View File

@ -7,6 +7,5 @@
#tabbar::tab #tabbar::tab
{ {
max-width: 250px;
max-height: 26px; max-height: 26px;
} }

View File

@ -93,9 +93,9 @@
} }
/*TabWidget*/ /*TabWidget*/
#tabwidget::tab-bar #tabbar::scroller
{ {
right: 26px; width: 0px;
} }
#tabwidget-button-opentabs #tabwidget-button-opentabs

View File

@ -9,7 +9,6 @@
#tabbar::tab #tabbar::tab
{ {
max-width: 250px;
height: 26px; height: 26px;
} }

View File

@ -7,6 +7,5 @@
#tabbar::tab #tabbar::tab
{ {
max-width: 250px;
max-height: 26px; max-height: 26px;
} }

View File

@ -103,9 +103,9 @@
} }
/*TabWidget*/ /*TabWidget*/
#tabwidget::tab-bar #tabbar::scroller
{ {
right: 17px; width: 0px;
} }
#tabwidget-button-opentabs #tabwidget-button-opentabs

View File

@ -9,7 +9,6 @@
#tabbar::tab #tabbar::tab
{ {
max-width: 250px;
height: 26px; height: 26px;
} }

View File

@ -20,11 +20,22 @@
#include "qupzilla.h" #include "qupzilla.h"
#include "webtab.h" #include "webtab.h"
#include "iconprovider.h" #include "iconprovider.h"
#include "toolbutton.h"
TabBar::TabBar(QupZilla* mainClass, QWidget* parent) : #define MAXIMUM_TAB_WIDTH 250
QTabBar(parent) #define MINIMUM_TAB_WIDTH 50
,p_QupZilla(mainClass) #ifdef Q_WS_WIN
,m_clickedTab(0) #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"); setObjectName("tabbar");
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
@ -34,6 +45,8 @@ TabBar::TabBar(QupZilla* mainClass, QWidget* parent) :
loadSettings(); loadSettings();
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &))); 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() void TabBar::loadSettings()
@ -53,15 +66,11 @@ void TabBar::contextMenuRequested(const QPoint &position)
int index = tabAt(position); int index = tabAt(position);
m_clickedTab = index; m_clickedTab = index;
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
if (!tabWidget)
return;
QMenu menu; QMenu menu;
menu.addAction(QIcon(":/icons/menu/popup.png"),tr("&New tab"), p_QupZilla, SLOT(addTab())); menu.addAction(QIcon(":/icons/menu/popup.png"),tr("&New tab"), p_QupZilla, SLOT(addTab()));
menu.addSeparator(); menu.addSeparator();
if (index!=-1) { if (index!=-1) {
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(m_clickedTab)); WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
if (!webTab) if (!webTab)
return; return;
if (p_QupZilla->weView(m_clickedTab)->isLoading()) 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(tr("&Duplicate Tab"), this, SLOT(duplicateTab()));
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"), 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 This Tab"), this, SLOT(bookmarkTab()));
menu.addAction(tr("Bookmark &All Tabs"), p_QupZilla, SLOT(bookmarkAllTabs())); menu.addAction(tr("Bookmark &All Tabs"), p_QupZilla, SLOT(bookmarkAllTabs()));
menu.addSeparator(); menu.addSeparator();
QAction* action = p_QupZilla->actionRestoreTab(); 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.addAction(action);
menu.addSeparator(); menu.addSeparator();
menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent())); menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent()));
menu.addAction(QIcon::fromTheme("window-close"),tr("Cl&ose"), this, SLOT(closeTab())); menu.addAction(QIcon::fromTheme("window-close"),tr("Cl&ose"), this, SLOT(closeTab()));
menu.addSeparator(); menu.addSeparator();
} else { } 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.addAction(tr("Bookmark &All Ta&bs"), p_QupZilla, SLOT(bookmarkAllTabs()));
menu.addSeparator(); menu.addSeparator();
QAction* action = menu.addAction(QIcon::fromTheme("user-trash"),tr("Restore &Closed Tab"), tabWidget, SLOT(restoreClosedTab())); QAction* action = menu.addAction(QIcon::fromTheme("user-trash"),tr("Restore &Closed Tab"), m_tabWidget, SLOT(restoreClosedTab()));
tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false); m_tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false);
} }
//Prevent choosing first option with double rightclick //Prevent choosing first option with double rightclick
@ -101,15 +110,25 @@ void TabBar::contextMenuRequested(const QPoint &position)
QSize TabBar::tabSizeHint(int index) const QSize TabBar::tabSizeHint(int index) const
{ {
QSize size = QTabBar::tabSizeHint(index); QSize size = QTabBar::tabSizeHint(index);
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget()); WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index));
if (tabWidget) {
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(index)); if (webTab && webTab->isPinned()) {
if (webTab && webTab->isPinned()) size.setWidth(PINNED_TAB_WIDTH);
#ifdef Q_WS_WIN } else {
size.setWidth(38); int availableWidth = width() - (PINNED_TAB_WIDTH * m_pinnedTabsCount) - m_tabWidget->buttonListTabs()->width();
#else int normalTabsCount = count() - m_pinnedTabsCount;
size.setWidth(31); if (availableWidth >= MAXIMUM_TAB_WIDTH * normalTabsCount)
#endif 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; return size;
} }
@ -131,11 +150,8 @@ void TabBar::tabInserted(int index)
void TabBar::showCloseButton(int index) void TabBar::showCloseButton(int index)
{ {
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
if (!tabWidget)
return;
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(index)); WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index));
if (webTab && webTab->isPinned()) if (webTab && webTab->isPinned())
return; return;
@ -161,11 +177,7 @@ void TabBar::updateCloseButton(int index)
if (!button) if (!button)
return; return;
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget()); WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index));
if (!tabWidget)
return;
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(index));
if (webTab && webTab->isPinned()) if (webTab && webTab->isPinned())
button->hide(); button->hide();
else else
@ -175,10 +187,10 @@ void TabBar::updateCloseButton(int index)
void TabBar::closeCurrentTab() void TabBar::closeCurrentTab()
{ {
int id = currentIndex(); int id = currentIndex();
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget()); if (id < 0)
if (!tabWidget || id < 0)
return; return;
tabWidget->closeTab(id);
m_tabWidget->closeTab(id);
} }
void TabBar::bookmarkTab() void TabBar::bookmarkTab()
@ -188,24 +200,32 @@ void TabBar::bookmarkTab()
void TabBar::pinTab() void TabBar::pinTab()
{ {
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget()); WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
if (!tabWidget)
return;
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(m_clickedTab));
if (!webTab) if (!webTab)
return; return;
webTab->pinTab(m_clickedTab); 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) void TabBar::mouseDoubleClickEvent(QMouseEvent* event)
{ {
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
if (!tabWidget)
return;
if (event->button() == Qt::LeftButton && tabAt(event->pos()) == -1) { 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; return;
} }
QTabBar::mouseDoubleClickEvent(event); QTabBar::mouseDoubleClickEvent(event);

View File

@ -27,6 +27,7 @@
#include <QSettings> #include <QSettings>
class QupZilla; class QupZilla;
class TabWidget;
class TabBar : public QTabBar class TabBar : public QTabBar
{ {
Q_OBJECT Q_OBJECT
@ -52,6 +53,9 @@ signals:
public slots: public slots:
private slots: private slots:
void pinnedTabAdded();
void pinnedTabClosed();
void contextMenuRequested(const QPoint &position); void contextMenuRequested(const QPoint &position);
void reloadTab() { emit reloadTab(m_clickedTab); } void reloadTab() { emit reloadTab(m_clickedTab); }
void stopTab() { emit stopTab(m_clickedTab); } void stopTab() { emit stopTab(m_clickedTab); }
@ -70,9 +74,13 @@ private:
// void tabInserted(int index); // void tabInserted(int index);
QupZilla* p_QupZilla; QupZilla* p_QupZilla;
TabWidget* m_tabWidget;
bool m_showCloseButtonWithOneTab; bool m_showCloseButtonWithOneTab;
bool m_showTabBarWithOneTab; bool m_showTabBarWithOneTab;
int m_clickedTab; int m_clickedTab;
int m_pinnedTabsCount;
}; };

View File

@ -106,7 +106,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) :
, m_locationBars(new QStackedWidget()) , m_locationBars(new QStackedWidget())
{ {
setObjectName("tabwidget"); setObjectName("tabwidget");
m_tabBar = new TabBar(p_QupZilla); m_tabBar = new TabBar(p_QupZilla, this);
setTabBar(m_tabBar); setTabBar(m_tabBar);
connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int))); connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
@ -140,7 +140,7 @@ void TabWidget::loadSettings()
{ {
QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat);
settings.beginGroup("Browser-Tabs-Settings"); 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(); m_hideTabBarWithOneTab = settings.value("hideTabsWithOneTab",false).toBool();
settings.endGroup(); settings.endGroup();
settings.beginGroup("Web-URL-Settings"); 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) void TabWidget::setTabText(int index, const QString& text)
{ {
QString newtext = text + " "; QString newtext = text;
if (WebTab* webTab = qobject_cast<WebTab*>(p_QupZilla->tabWidget()->widget(index)) ) { if (WebTab* webTab = qobject_cast<WebTab*>(p_QupZilla->tabWidget()->widget(index)) ) {
if (webTab->isPinned()) if (webTab->isPinned())
@ -279,9 +279,10 @@ void TabWidget::closeTab(int index)
if (!webView) if (!webView)
return; return;
if (webView->webTab()->isPinned())
emit pinnedTabClosed();
m_locationBars->removeWidget(webView->webTab()->locationBar()); 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(wantsCloseTab(int)), this, SLOT(closeTab(int)));
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)));
@ -497,8 +498,10 @@ void TabWidget::restorePinnedTabs()
addedIndex = addView(url); addedIndex = addView(url);
} }
WebTab* webTab = (WebTab*)widget(addedIndex); WebTab* webTab = (WebTab*)widget(addedIndex);
if (webTab) if (webTab) {
webTab->setPinned(true); webTab->setPinned(true);
emit pinnedTabAdded();
}
m_tabBar->moveTab(addedIndex, i); m_tabBar->moveTab(addedIndex, i);
m_tabBar->updateCloseButton(i); m_tabBar->updateCloseButton(i);

View File

@ -59,6 +59,9 @@ public:
QStackedWidget* locationBars() { return m_locationBars; } QStackedWidget* locationBars() { return m_locationBars; }
ToolButton* buttonListTabs() { return m_buttonListTabs; } ToolButton* buttonListTabs() { return m_buttonListTabs; }
signals:
void pinnedTabClosed();
void pinnedTabAdded();
public slots: public slots:
void closeTab(int index=-1); void closeTab(int index=-1);

View File

@ -6,7 +6,7 @@
#include "qupzilla.h" #include "qupzilla.h"
WebInspectorDockWidget::WebInspectorDockWidget(QupZilla* mainClass) WebInspectorDockWidget::WebInspectorDockWidget(QupZilla* mainClass)
: QDockWidget() : QDockWidget(mainClass)
, p_QupZilla(mainClass) , p_QupZilla(mainClass)
, m_inspector(0) , m_inspector(0)
{ {