1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

TabBar: Initialize pinned tab width from real tab

Calculates the padding between tab border and icon from tabRect
instead of using style pixel metric which was oftentimes incorrect.

Pinned tabs should now have correct size and icon be perfectly centered
with all possible widget and qss styles.
This commit is contained in:
David Rosca 2018-02-02 08:54:45 +01:00
parent 01c5397fef
commit 9f4ac24cf8
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8

View File

@ -51,7 +51,7 @@ class TabBarTabMetrics : public QWidget
Q_PROPERTY(int pinnedWidth READ pinnedWidth WRITE setPinnedWidth) Q_PROPERTY(int pinnedWidth READ pinnedWidth WRITE setPinnedWidth)
public: public:
void init(TabBar *t) void init()
{ {
if (!m_metrics.isEmpty()) { if (!m_metrics.isEmpty()) {
return; return;
@ -60,7 +60,7 @@ public:
m_metrics[1] = 100; m_metrics[1] = 100;
m_metrics[2] = 100; m_metrics[2] = 100;
m_metrics[3] = 100; m_metrics[3] = 100;
m_metrics[4] = t->iconButtonSize().width() + t->style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr, t); m_metrics[4] = -1; // Will be initialized from TabBar
} }
int normalMaxWidth() const { return m_metrics.value(0); } int normalMaxWidth() const { return m_metrics.value(0); }
@ -111,7 +111,7 @@ 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); tabMetrics()->init();
if (mApp->isPrivate()) { if (mApp->isPrivate()) {
QLabel* privateBrowsing = new QLabel(this); QLabel* privateBrowsing = new QLabel(this);
@ -292,7 +292,7 @@ int TabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const
{ {
switch (sizeType) { switch (sizeType) {
case ComboTabBar::PinnedTabWidth: case ComboTabBar::PinnedTabWidth:
return tabMetrics()->pinnedWidth(); return tabMetrics()->pinnedWidth() > 0 ? tabMetrics()->pinnedWidth() : 32;
case ComboTabBar::ActiveTabMinimumWidth: case ComboTabBar::ActiveTabMinimumWidth:
return tabMetrics()->activeMinWidth(); return tabMetrics()->activeMinWidth();
@ -455,6 +455,22 @@ void TabBar::tabInserted(int index)
{ {
Q_UNUSED(index) Q_UNUSED(index)
// Initialize pinned tab metrics
if (tabMetrics()->pinnedWidth() == -1) {
QTimer::singleShot(0, this, [this]() {
if (tabMetrics()->pinnedWidth() != -1) {
return;
}
QWidget *w = tabButton(0, iconButtonPosition());
const QRect r = tabRect(0);
if (w && r.isValid()) {
const int padding = w->geometry().x() - r.x();
tabMetrics()->setPinnedWidth(iconButtonSize().width() + padding * 2);
setUpLayout();
}
});
}
setVisible(!(count() <= 1 && m_hideTabBarWithOneTab)); setVisible(!(count() <= 1 && m_hideTabBarWithOneTab));
} }