diff --git a/src/lib/tabwidget/combotabbar.cpp b/src/lib/tabwidget/combotabbar.cpp index e0bf03bf0..2adfa02a8 100644 --- a/src/lib/tabwidget/combotabbar.cpp +++ b/src/lib/tabwidget/combotabbar.cpp @@ -429,6 +429,8 @@ void ComboTabBar::setTabsClosable(bool closable) void ComboTabBar::setTabButton(int index, QTabBar::ButtonPosition position, QWidget* widget) { + if (widget) + widget->setMinimumSize(closeButtonSize()); localTabBar(index)->setTabButton(toLocalIndex(index), position, widget); } @@ -553,6 +555,7 @@ void ComboTabBar::insertCloseButton(int index) } QAbstractButton* closeButton = new CloseButton(this); + closeButton->setFixedSize(closeButtonSize()); closeButton->setToolTip(m_closeButtonsToolTip); connect(closeButton, SIGNAL(clicked()), this, SLOT(closeTabFromButton())); m_mainTabBar->setTabButton(index, closeButtonPosition(), closeButton); @@ -727,16 +730,31 @@ int ComboTabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const return -1; } -QTabBar::ButtonPosition ComboTabBar::iconButtonPosition() +QTabBar::ButtonPosition ComboTabBar::iconButtonPosition() const { 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); } +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 { return (index >= 0 && index < count()); @@ -1563,21 +1581,6 @@ CloseButton::CloseButton(QWidget* parent) setObjectName("combotabbar_tabs_close_button"); setFocusPolicy(Qt::NoFocus); 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) diff --git a/src/lib/tabwidget/combotabbar.h b/src/lib/tabwidget/combotabbar.h index 64c947e76..bfbca9429 100644 --- a/src/lib/tabwidget/combotabbar.h +++ b/src/lib/tabwidget/combotabbar.h @@ -122,8 +122,11 @@ public: void insertCloseButton(int index); void setCloseButtonsToolTip(const QString &tip); - QTabBar::ButtonPosition iconButtonPosition(); - QTabBar::ButtonPosition closeButtonPosition(); + QTabBar::ButtonPosition iconButtonPosition() const; + QTabBar::ButtonPosition closeButtonPosition() const; + + QSize iconButtonSize() const; + QSize closeButtonSize() const; bool validIndex(int index) const; void setCurrentNextEnabledIndex(int offset); @@ -328,9 +331,6 @@ class CloseButton : public QAbstractButton public: CloseButton(QWidget* parent = 0); - QSize sizeHint() const; - QSize minimumSizeHint() const; - void enterEvent(QEvent* event); void leaveEvent(QEvent* event); void paintEvent(QPaintEvent* event); diff --git a/src/lib/tabwidget/tabbar.cpp b/src/lib/tabwidget/tabbar.cpp index 6c88f3c85..df940cabd 100644 --- a/src/lib/tabwidget/tabbar.cpp +++ b/src/lib/tabwidget/tabbar.cpp @@ -258,7 +258,7 @@ int TabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const switch (sizeType) { 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::NormalTabMinimumWidth: diff --git a/src/lib/tabwidget/tabicon.cpp b/src/lib/tabwidget/tabicon.cpp index eb53a988e..e720d45bf 100644 --- a/src/lib/tabwidget/tabicon.cpp +++ b/src/lib/tabwidget/tabicon.cpp @@ -39,9 +39,7 @@ TabIcon::TabIcon(QWidget* parent) m_updateTimer->setInterval(ANIMATION_INTERVAL); connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateAnimationFrame())); - static int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this); - static int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, this); - resize(width, height); + resize(16, 16); setIcon(IconProvider::emptyWebIcon()); }