From eb90925a324963d1bc8c2ada070161769a303833 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 12 Feb 2018 16:16:53 +0100 Subject: [PATCH] TabWidget: Add moveTab() method that supports moving tabs between both tabbars --- src/lib/tabwidget/tabmodel.cpp | 17 ++--------------- src/lib/tabwidget/tabwidget.cpp | 13 +++++++++++++ src/lib/tabwidget/tabwidget.h | 1 + 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/lib/tabwidget/tabmodel.cpp b/src/lib/tabwidget/tabmodel.cpp index a2725ca2f..1b790e87f 100644 --- a/src/lib/tabwidget/tabmodel.cpp +++ b/src/lib/tabwidget/tabmodel.cpp @@ -186,21 +186,8 @@ bool TabModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro WebTab *tab = mimeData->tab(); if (tab->browserWindow() == m_window) { - if (tab->isPinned()) { - if (row < 0) { - 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++; - } + if (row < 0) { + row = tab->isPinned() ? m_window->tabWidget()->pinnedTabsCount() : m_window->tabWidget()->count(); } tab->moveTab(row > mimeData->tab()->tabIndex() ? row - 1 : row); } else { diff --git a/src/lib/tabwidget/tabwidget.cpp b/src/lib/tabwidget/tabwidget.cpp index 8c9b00c62..d4cbb69be 100644 --- a/src/lib/tabwidget/tabwidget.cpp +++ b/src/lib/tabwidget/tabwidget.cpp @@ -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) { const int newIndex = TabStackedWidget::pinUnPinTab(index, title); diff --git a/src/lib/tabwidget/tabwidget.h b/src/lib/tabwidget/tabwidget.h index ff608d18d..2098f40d7 100644 --- a/src/lib/tabwidget/tabwidget.h +++ b/src/lib/tabwidget/tabwidget.h @@ -96,6 +96,7 @@ public: ToolButton* buttonClosedTabs() const; AddTabButton* buttonAddTab() const; + void moveTab(int from, int to); int pinUnPinTab(int index, const QString &title = QString()); void detachTab(WebTab* tab);