From 516bd9208901a0d89977923feb2d03a79b157d01 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 8 Jan 2018 21:35:18 +0100 Subject: [PATCH] TabBar: Allow to change width of tabs using style sheets It can be set in themes or in userChrome.css as in example. /* userChrome.css */ TabBarTabMetrics { qproperty-normalMaxWidth: 250; qproperty-normalMinWidth: 150; qproperty-activeMinWidth: 150; qproperty-overflowedWidth: 150; qproperty-pinnedWidth: 35; } --- src/lib/tabwidget/tabbar.cpp | 57 ++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/src/lib/tabwidget/tabbar.cpp b/src/lib/tabwidget/tabbar.cpp index 8f3c756d3..7672fb58b 100644 --- a/src/lib/tabwidget/tabbar.cpp +++ b/src/lib/tabwidget/tabbar.cpp @@ -41,6 +41,49 @@ #define MIMETYPE QSL("application/falkon.tabbar.tab") +class TabBarTabMetrics : public QWidget +{ + Q_OBJECT + Q_PROPERTY(int normalMaxWidth READ normalMaxWidth WRITE setNormalMaxWidth) + Q_PROPERTY(int normalMinWidth READ normalMinWidth WRITE setNormalMinWidth) + Q_PROPERTY(int activeMinWidth READ activeMinWidth WRITE setActiveMinWidth) + Q_PROPERTY(int overflowedWidth READ overflowedWidth WRITE setOverflowedWidth) + Q_PROPERTY(int pinnedWidth READ pinnedWidth WRITE setPinnedWidth) + +public: + void init(TabBar *t) + { + if (!m_metrics.isEmpty()) { + return; + } + m_metrics[0] = 250; + m_metrics[1] = 100; + m_metrics[2] = 100; + m_metrics[3] = 100; + m_metrics[4] = t->iconButtonSize().width() + t->style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr, t); + } + + int normalMaxWidth() const { return m_metrics.value(0); } + void setNormalMaxWidth(int value) { m_metrics[0] = value; } + + int normalMinWidth() const { return m_metrics.value(1); } + void setNormalMinWidth(int value) { m_metrics[1] = value; } + + int activeMinWidth() const { return m_metrics.value(2); } + void setActiveMinWidth(int value) { m_metrics[2] = value; } + + int overflowedWidth() const { return m_metrics.value(3); } + void setOverflowedWidth(int value) { m_metrics[3] = value; } + + int pinnedWidth() const { return m_metrics.value(4); } + void setPinnedWidth(int value) { m_metrics[4] = value; } + +private: + QHash m_metrics; +}; + +Q_GLOBAL_STATIC(TabBarTabMetrics, tabMetrics) + TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget) : ComboTabBar() , m_window(window) @@ -68,6 +111,8 @@ TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget) setCloseButtonsToolTip(BrowserWindow::tr("Close Tab")); connect(this, SIGNAL(overFlowChanged(bool)), this, SLOT(overflowChanged(bool))); + tabMetrics()->init(this); + if (mApp->isPrivate()) { QLabel* privateBrowsing = new QLabel(this); privateBrowsing->setObjectName(QSL("private-browsing-icon")); @@ -247,15 +292,19 @@ int TabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const { switch (sizeType) { case ComboTabBar::PinnedTabWidth: - return iconButtonSize().width() + style()->pixelMetric(QStyle::PM_TabBarTabHSpace, 0, this); + return tabMetrics()->pinnedWidth(); case ComboTabBar::ActiveTabMinimumWidth: + return tabMetrics()->activeMinWidth(); + case ComboTabBar::NormalTabMinimumWidth: + return tabMetrics()->normalMinWidth(); + case ComboTabBar::OverflowedTabWidth: - return 100; + return tabMetrics()->overflowedWidth(); case ComboTabBar::NormalTabMaximumWidth: - return 250; + return tabMetrics()->normalMaxWidth(); case ComboTabBar::ExtraReservedWidth: return m_tabWidget->extraReservedWidth(); @@ -659,3 +708,5 @@ void TabBar::dropEvent(QDropEvent* event) } } } + +#include "tabbar.moc"