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:
parent
01c5397fef
commit
9f4ac24cf8
|
@ -51,7 +51,7 @@ class TabBarTabMetrics : public QWidget
|
|||
Q_PROPERTY(int pinnedWidth READ pinnedWidth WRITE setPinnedWidth)
|
||||
|
||||
public:
|
||||
void init(TabBar *t)
|
||||
void init()
|
||||
{
|
||||
if (!m_metrics.isEmpty()) {
|
||||
return;
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
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);
|
||||
m_metrics[4] = -1; // Will be initialized from TabBar
|
||||
}
|
||||
|
||||
int normalMaxWidth() const { return m_metrics.value(0); }
|
||||
|
@ -111,7 +111,7 @@ TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget)
|
|||
setCloseButtonsToolTip(BrowserWindow::tr("Close Tab"));
|
||||
connect(this, SIGNAL(overFlowChanged(bool)), this, SLOT(overflowChanged(bool)));
|
||||
|
||||
tabMetrics()->init(this);
|
||||
tabMetrics()->init();
|
||||
|
||||
if (mApp->isPrivate()) {
|
||||
QLabel* privateBrowsing = new QLabel(this);
|
||||
|
@ -292,7 +292,7 @@ int TabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const
|
|||
{
|
||||
switch (sizeType) {
|
||||
case ComboTabBar::PinnedTabWidth:
|
||||
return tabMetrics()->pinnedWidth();
|
||||
return tabMetrics()->pinnedWidth() > 0 ? tabMetrics()->pinnedWidth() : 32;
|
||||
|
||||
case ComboTabBar::ActiveTabMinimumWidth:
|
||||
return tabMetrics()->activeMinWidth();
|
||||
|
@ -455,6 +455,22 @@ void TabBar::tabInserted(int 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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user