mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
ComboTabBar: Add support for tabPadding property
Workarounds bug where tabs have zero padding when styled using style sheets.
This commit is contained in:
parent
e617f3f6ec
commit
4c7eaf0f9f
@ -994,6 +994,16 @@ TabBarHelper::TabBarHelper(bool isPinnedTabBar, ComboTabBar* comboTabBar)
|
||||
connect(this, SIGNAL(tabMoved(int,int)), this, SLOT(tabWasMoved(int,int)));
|
||||
}
|
||||
|
||||
int TabBarHelper::tabPadding() const
|
||||
{
|
||||
return m_tabPadding;
|
||||
}
|
||||
|
||||
void TabBarHelper::setTabPadding(int padding)
|
||||
{
|
||||
m_tabPadding = padding;
|
||||
}
|
||||
|
||||
void TabBarHelper::setTabButton(int index, QTabBar::ButtonPosition position, QWidget* widget)
|
||||
{
|
||||
QTabBar::setTabButton(index, position, widget);
|
||||
@ -1360,6 +1370,13 @@ void TabBarHelper::initStyleOption(QStyleOptionTab* option, int tabIndex) const
|
||||
{
|
||||
QTabBar::initStyleOption(option, tabIndex);
|
||||
|
||||
// Workaround zero padding when tabs are styled using style sheets
|
||||
if (m_tabPadding > 0 && (tabIndex != currentIndex() || m_dragInProgress)) {
|
||||
const QRect textRect = style()->subElementRect(QStyle::SE_TabBarTabText, option, this);
|
||||
const int width = textRect.width() - 2 * m_tabPadding;
|
||||
option->text = option->fontMetrics.elidedText(tabText(tabIndex), elideMode(), width, Qt::TextShowMnemonic);
|
||||
}
|
||||
|
||||
// Bespin doesn't highlight current tab when there is only one tab in tabbar
|
||||
static int isBespin = -1;
|
||||
|
||||
|
@ -226,10 +226,14 @@ private:
|
||||
class FALKON_EXPORT TabBarHelper : public QTabBar
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int tabPadding READ tabPadding WRITE setTabPadding)
|
||||
|
||||
public:
|
||||
explicit TabBarHelper(bool isPinnedTabBar, ComboTabBar* comboTabBar);
|
||||
|
||||
int tabPadding() const;
|
||||
void setTabPadding(int padding);
|
||||
|
||||
void setTabButton(int index, QTabBar::ButtonPosition position, QWidget* widget);
|
||||
|
||||
QSize tabSizeHint(int index) const;
|
||||
@ -274,6 +278,7 @@ private:
|
||||
ComboTabBar* m_comboTabBar;
|
||||
QScrollArea* m_scrollArea;
|
||||
|
||||
int m_tabPadding = -1;
|
||||
int m_pressedIndex;
|
||||
int m_pressedGlobalX;
|
||||
bool m_dragInProgress;
|
||||
|
Loading…
Reference in New Issue
Block a user