1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

TabWidget: Add moveTab() method that supports moving tabs between both tabbars

This commit is contained in:
David Rosca 2018-02-12 16:16:53 +01:00
parent 802e447c0c
commit eb90925a32
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
3 changed files with 16 additions and 15 deletions

View File

@ -186,21 +186,8 @@ bool TabModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro
WebTab *tab = mimeData->tab(); WebTab *tab = mimeData->tab();
if (tab->browserWindow() == m_window) { if (tab->browserWindow() == m_window) {
if (tab->isPinned()) { if (row < 0) {
if (row < 0) { row = tab->isPinned() ? m_window->tabWidget()->pinnedTabsCount() : m_window->tabWidget()->count();
row = m_window->tabWidget()->pinnedTabsCount();
}
if (row > m_window->tabWidget()->pinnedTabsCount()) {
tab->togglePinned();
}
} else {
if (row < 0) {
row = m_window->tabWidget()->count();
}
if (row < m_window->tabWidget()->pinnedTabsCount()) {
tab->togglePinned();
row++;
}
} }
tab->moveTab(row > mimeData->tab()->tabIndex() ? row - 1 : row); tab->moveTab(row > mimeData->tab()->tabIndex() ? row - 1 : row);
} else { } else {

View File

@ -649,6 +649,19 @@ void TabWidget::closeToLeft(int index)
} }
} }
void TabWidget::moveTab(int from, int to)
{
WebTab *tab = webTab(from);
if (!tab) {
return;
}
// (Un)pin tab when needed
if ((tab->isPinned() && to >= pinnedTabsCount()) || (!tab->isPinned() && to < pinnedTabsCount())) {
tab->togglePinned();
}
TabStackedWidget::moveTab(tab->tabIndex(), to);
}
int TabWidget::pinUnPinTab(int index, const QString &title) int TabWidget::pinUnPinTab(int index, const QString &title)
{ {
const int newIndex = TabStackedWidget::pinUnPinTab(index, title); const int newIndex = TabStackedWidget::pinUnPinTab(index, title);

View File

@ -96,6 +96,7 @@ public:
ToolButton* buttonClosedTabs() const; ToolButton* buttonClosedTabs() const;
AddTabButton* buttonAddTab() const; AddTabButton* buttonAddTab() const;
void moveTab(int from, int to);
int pinUnPinTab(int index, const QString &title = QString()); int pinUnPinTab(int index, const QString &title = QString());
void detachTab(WebTab* tab); void detachTab(WebTab* tab);