mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-21 03:06:34 +01:00
TabBar: Improve logic to calculate pinned tab width
This commit is contained in:
parent
74b9019a01
commit
ac792de566
@ -429,6 +429,8 @@ void ComboTabBar::setTabsClosable(bool closable)
|
|||||||
|
|
||||||
void ComboTabBar::setTabButton(int index, QTabBar::ButtonPosition position, QWidget* widget)
|
void ComboTabBar::setTabButton(int index, QTabBar::ButtonPosition position, QWidget* widget)
|
||||||
{
|
{
|
||||||
|
if (widget)
|
||||||
|
widget->setMinimumSize(closeButtonSize());
|
||||||
localTabBar(index)->setTabButton(toLocalIndex(index), position, widget);
|
localTabBar(index)->setTabButton(toLocalIndex(index), position, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,6 +555,7 @@ void ComboTabBar::insertCloseButton(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QAbstractButton* closeButton = new CloseButton(this);
|
QAbstractButton* closeButton = new CloseButton(this);
|
||||||
|
closeButton->setFixedSize(closeButtonSize());
|
||||||
closeButton->setToolTip(m_closeButtonsToolTip);
|
closeButton->setToolTip(m_closeButtonsToolTip);
|
||||||
connect(closeButton, SIGNAL(clicked()), this, SLOT(closeTabFromButton()));
|
connect(closeButton, SIGNAL(clicked()), this, SLOT(closeTabFromButton()));
|
||||||
m_mainTabBar->setTabButton(index, closeButtonPosition(), closeButton);
|
m_mainTabBar->setTabButton(index, closeButtonPosition(), closeButton);
|
||||||
@ -727,16 +730,31 @@ int ComboTabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTabBar::ButtonPosition ComboTabBar::iconButtonPosition()
|
QTabBar::ButtonPosition ComboTabBar::iconButtonPosition() const
|
||||||
{
|
{
|
||||||
return (closeButtonPosition() == QTabBar::RightSide ? QTabBar::LeftSide : QTabBar::RightSide);
|
return (closeButtonPosition() == QTabBar::RightSide ? QTabBar::LeftSide : QTabBar::RightSide);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTabBar::ButtonPosition ComboTabBar::closeButtonPosition()
|
QTabBar::ButtonPosition ComboTabBar::closeButtonPosition() const
|
||||||
{
|
{
|
||||||
return (QTabBar::ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, this);
|
return (QTabBar::ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSize ComboTabBar::iconButtonSize() const
|
||||||
|
{
|
||||||
|
QSize s = closeButtonSize();
|
||||||
|
s.setWidth(std::max(16, s.width()));
|
||||||
|
s.setHeight(std::max(16, s.height()));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize ComboTabBar::closeButtonSize() const
|
||||||
|
{
|
||||||
|
int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this);
|
||||||
|
int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, this);
|
||||||
|
return QSize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
bool ComboTabBar::validIndex(int index) const
|
bool ComboTabBar::validIndex(int index) const
|
||||||
{
|
{
|
||||||
return (index >= 0 && index < count());
|
return (index >= 0 && index < count());
|
||||||
@ -1563,21 +1581,6 @@ CloseButton::CloseButton(QWidget* parent)
|
|||||||
setObjectName("combotabbar_tabs_close_button");
|
setObjectName("combotabbar_tabs_close_button");
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
setCursor(Qt::ArrowCursor);
|
setCursor(Qt::ArrowCursor);
|
||||||
|
|
||||||
resize(sizeHint());
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize CloseButton::sizeHint() const
|
|
||||||
{
|
|
||||||
ensurePolished();
|
|
||||||
static int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this);
|
|
||||||
static int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, this);
|
|
||||||
return QSize(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize CloseButton::minimumSizeHint() const
|
|
||||||
{
|
|
||||||
return sizeHint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloseButton::enterEvent(QEvent* event)
|
void CloseButton::enterEvent(QEvent* event)
|
||||||
|
@ -122,8 +122,11 @@ public:
|
|||||||
void insertCloseButton(int index);
|
void insertCloseButton(int index);
|
||||||
void setCloseButtonsToolTip(const QString &tip);
|
void setCloseButtonsToolTip(const QString &tip);
|
||||||
|
|
||||||
QTabBar::ButtonPosition iconButtonPosition();
|
QTabBar::ButtonPosition iconButtonPosition() const;
|
||||||
QTabBar::ButtonPosition closeButtonPosition();
|
QTabBar::ButtonPosition closeButtonPosition() const;
|
||||||
|
|
||||||
|
QSize iconButtonSize() const;
|
||||||
|
QSize closeButtonSize() const;
|
||||||
|
|
||||||
bool validIndex(int index) const;
|
bool validIndex(int index) const;
|
||||||
void setCurrentNextEnabledIndex(int offset);
|
void setCurrentNextEnabledIndex(int offset);
|
||||||
@ -328,9 +331,6 @@ class CloseButton : public QAbstractButton
|
|||||||
public:
|
public:
|
||||||
CloseButton(QWidget* parent = 0);
|
CloseButton(QWidget* parent = 0);
|
||||||
|
|
||||||
QSize sizeHint() const;
|
|
||||||
QSize minimumSizeHint() const;
|
|
||||||
|
|
||||||
void enterEvent(QEvent* event);
|
void enterEvent(QEvent* event);
|
||||||
void leaveEvent(QEvent* event);
|
void leaveEvent(QEvent* event);
|
||||||
void paintEvent(QPaintEvent* event);
|
void paintEvent(QPaintEvent* event);
|
||||||
|
@ -258,7 +258,7 @@ int TabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const
|
|||||||
|
|
||||||
switch (sizeType) {
|
switch (sizeType) {
|
||||||
case ComboTabBar::PinnedTabWidth:
|
case ComboTabBar::PinnedTabWidth:
|
||||||
return 16 + style()->pixelMetric(QStyle::PM_TabBarTabHSpace, 0, this);
|
return iconButtonSize().width() + style()->pixelMetric(QStyle::PM_TabBarTabHSpace, 0, this);
|
||||||
|
|
||||||
case ComboTabBar::ActiveTabMinimumWidth:
|
case ComboTabBar::ActiveTabMinimumWidth:
|
||||||
case ComboTabBar::NormalTabMinimumWidth:
|
case ComboTabBar::NormalTabMinimumWidth:
|
||||||
|
@ -39,9 +39,7 @@ TabIcon::TabIcon(QWidget* parent)
|
|||||||
m_updateTimer->setInterval(ANIMATION_INTERVAL);
|
m_updateTimer->setInterval(ANIMATION_INTERVAL);
|
||||||
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateAnimationFrame()));
|
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateAnimationFrame()));
|
||||||
|
|
||||||
static int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this);
|
resize(16, 16);
|
||||||
static int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, this);
|
|
||||||
resize(width, height);
|
|
||||||
|
|
||||||
setIcon(IconProvider::emptyWebIcon());
|
setIcon(IconProvider::emptyWebIcon());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user