mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
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; }
This commit is contained in:
parent
bfc3b0bf4a
commit
516bd92089
@ -41,6 +41,49 @@
|
|||||||
|
|
||||||
#define MIMETYPE QSL("application/falkon.tabbar.tab")
|
#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<int, int> m_metrics;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC(TabBarTabMetrics, tabMetrics)
|
||||||
|
|
||||||
TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget)
|
TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget)
|
||||||
: ComboTabBar()
|
: ComboTabBar()
|
||||||
, m_window(window)
|
, m_window(window)
|
||||||
@ -68,6 +111,8 @@ TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget)
|
|||||||
setCloseButtonsToolTip(BrowserWindow::tr("Close Tab"));
|
setCloseButtonsToolTip(BrowserWindow::tr("Close Tab"));
|
||||||
connect(this, SIGNAL(overFlowChanged(bool)), this, SLOT(overflowChanged(bool)));
|
connect(this, SIGNAL(overFlowChanged(bool)), this, SLOT(overflowChanged(bool)));
|
||||||
|
|
||||||
|
tabMetrics()->init(this);
|
||||||
|
|
||||||
if (mApp->isPrivate()) {
|
if (mApp->isPrivate()) {
|
||||||
QLabel* privateBrowsing = new QLabel(this);
|
QLabel* privateBrowsing = new QLabel(this);
|
||||||
privateBrowsing->setObjectName(QSL("private-browsing-icon"));
|
privateBrowsing->setObjectName(QSL("private-browsing-icon"));
|
||||||
@ -247,15 +292,19 @@ int TabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const
|
|||||||
{
|
{
|
||||||
switch (sizeType) {
|
switch (sizeType) {
|
||||||
case ComboTabBar::PinnedTabWidth:
|
case ComboTabBar::PinnedTabWidth:
|
||||||
return iconButtonSize().width() + style()->pixelMetric(QStyle::PM_TabBarTabHSpace, 0, this);
|
return tabMetrics()->pinnedWidth();
|
||||||
|
|
||||||
case ComboTabBar::ActiveTabMinimumWidth:
|
case ComboTabBar::ActiveTabMinimumWidth:
|
||||||
|
return tabMetrics()->activeMinWidth();
|
||||||
|
|
||||||
case ComboTabBar::NormalTabMinimumWidth:
|
case ComboTabBar::NormalTabMinimumWidth:
|
||||||
|
return tabMetrics()->normalMinWidth();
|
||||||
|
|
||||||
case ComboTabBar::OverflowedTabWidth:
|
case ComboTabBar::OverflowedTabWidth:
|
||||||
return 100;
|
return tabMetrics()->overflowedWidth();
|
||||||
|
|
||||||
case ComboTabBar::NormalTabMaximumWidth:
|
case ComboTabBar::NormalTabMaximumWidth:
|
||||||
return 250;
|
return tabMetrics()->normalMaxWidth();
|
||||||
|
|
||||||
case ComboTabBar::ExtraReservedWidth:
|
case ComboTabBar::ExtraReservedWidth:
|
||||||
return m_tabWidget->extraReservedWidth();
|
return m_tabWidget->extraReservedWidth();
|
||||||
@ -659,3 +708,5 @@ void TabBar::dropEvent(QDropEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "tabbar.moc"
|
||||||
|
Loading…
Reference in New Issue
Block a user