1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

TabStackedWidget: Cleanup pinUnPinTab code

This commit is contained in:
David Rosca 2015-10-14 22:50:57 +02:00
parent 398232246e
commit 1f32a018f5

View File

@ -253,33 +253,28 @@ void TabStackedWidget::setTabToolTip(int index, const QString &tip)
int TabStackedWidget::pinUnPinTab(int index, const QString &title) int TabStackedWidget::pinUnPinTab(int index, const QString &title)
{ {
int newIndex = -1;
QWidget* widget = m_stack->widget(index); QWidget* widget = m_stack->widget(index);
QWidget* currentWidget = m_stack->currentWidget(); QWidget* currentWidget = m_stack->currentWidget();
bool makePinned = false;
m_tabBar->m_blockCurrentChangedSignal = true; if (!widget || !currentWidget)
return -1;
if (widget) { bool makePinned = index >= m_tabBar->pinnedTabsCount();
makePinned = index >= m_tabBar->pinnedTabsCount();
QWidget* button = m_tabBar->tabButton(index, m_tabBar->iconButtonPosition()); QWidget* button = m_tabBar->tabButton(index, m_tabBar->iconButtonPosition());
m_tabBar->m_blockCurrentChangedSignal = true;
m_tabBar->setTabButton(index, m_tabBar->iconButtonPosition(), 0); m_tabBar->setTabButton(index, m_tabBar->iconButtonPosition(), 0);
m_stack->removeWidget(widget); m_stack->removeWidget(widget);
newIndex = insertTab(makePinned ? 0 : m_tabBar->pinnedTabsCount(), widget, title, makePinned); int newIndex = insertTab(makePinned ? 0 : m_tabBar->pinnedTabsCount(), widget, title, makePinned);
m_tabBar->setTabButton(newIndex, m_tabBar->iconButtonPosition(), button); m_tabBar->setTabButton(newIndex, m_tabBar->iconButtonPosition(), button);
}
m_tabBar->m_blockCurrentChangedSignal = false; m_tabBar->m_blockCurrentChangedSignal = false;
// Restore current index // Restore current widget
setCurrentWidget(currentWidget); setCurrentWidget(currentWidget);
if (widget) {
emit pinStateChanged(newIndex, makePinned); emit pinStateChanged(newIndex, makePinned);
}
return newIndex; return newIndex;
} }