Skip to content

Commit

Permalink
chore:标签拖拽优化
Browse files Browse the repository at this point in the history
Description:标签拖到另个窗口标签栏不释放再拖回原窗口恢复内容

Log:标签拖到另个窗口标签栏不释放再拖回原窗口内容出错

link:无
  • Loading branch information
ut000616 committed Aug 12, 2020
1 parent c8cd1cc commit 12d3e19
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/tabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ QMimeData* Tabbar::createMimeDataFromTab(int index, const QStyleOptionTab &optio
mimeData->setData("dedit/tabbar", tabName.toUtf8());
mimeData->removeFormat("text/plain");

// window->closeTab();
// window->removeWrapper(fileAt(index));
return mimeData;
}

Expand All @@ -296,11 +298,12 @@ void Tabbar::insertFromMimeDataOnDragEnter(int index, const QMimeData *source)
if (source == nullptr) {
return;
}

//qDebug() << "insertFromMimeDataOnDragEnter";
const QString tabName = QString::fromUtf8(source->data("dedit/tabbar"));
QVariant pVar = source->property("wrapper");
EditWrapper *wrapper = static_cast<EditWrapper *>(pVar.value<void *>());
Window *window = static_cast<Window *>(this->window());
// EditWrapper *wrapper = window->addTab();

if (!wrapper) {
return;
Expand All @@ -318,7 +321,7 @@ void Tabbar::insertFromMimeData(int index, const QMimeData *source)
if (source == nullptr) {
return;
}

//qDebug() << "insertFromMimeData";
const QString tabName = QString::fromUtf8(source->data("dedit/tabbar"));
QVariant pVar = source->property("wrapper");
EditWrapper *wrapper = static_cast<EditWrapper *>(pVar.value<void *>());
Expand Down Expand Up @@ -505,24 +508,28 @@ void Tabbar::showTabs()

void Tabbar::handleTabReleased(int index)
{
const QString tabPath = fileAt(index);
const QString tabName = textAt(index);

QString path = m_listOldTabPath.value(index);
int newIndex = m_tabPaths.indexOf(path);
const QString tabPath = fileAt(newIndex);
const QString tabName = textAt(newIndex);
//qDebug() << "handleTabReleased" << index << newIndex;
Window *window = static_cast<Window *>(this->window());
EditWrapper *wrapper = window->wrapper(tabPath);
StartManager::instance()->createWindowFromWrapper(tabName, tabPath, wrapper, wrapper->textEditor()->document()->isModified());

closeTab(index);
closeTab(newIndex);
//qDebug() << "closeTab(index);" << index;
// remove wrapper from window, not delete.
window->removeWrapper(tabPath, false);
}

void Tabbar::handleTabIsRemoved(int index)
{
//qDebug() << "handleTabIsRemoved";
// QString path = m_listOldTabPath.value(index);
// int newIndex = m_tabPaths.indexOf(path);
//qDebug() << "handleTabIsRemoved" << index;
const QString filePath = m_tabPaths.at(index);
QString sss = filePath;
Window *window = static_cast<Window *>(this->window());

m_tabPaths.removeAt(index);
Expand All @@ -532,7 +539,7 @@ void Tabbar::handleTabIsRemoved(int index)

void Tabbar::handleTabDroped(int index, Qt::DropAction, QObject *target)
{
// qDebug() << "handleTabDroped";
//qDebug() << "handleTabDroped";
Tabbar *tabbar = qobject_cast<Tabbar *>(target);

if (tabbar == nullptr) {
Expand All @@ -543,6 +550,7 @@ void Tabbar::handleTabDroped(int index, Qt::DropAction, QObject *target)
} else {
QString path = m_listOldTabPath.value(index);
int newIndex = m_tabPaths.indexOf(path);
//qDebug() << "newIndex" << newIndex;
closeTab(newIndex);
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,10 +1610,22 @@ void Window::handleCurrentChanged(const int &index)
}

const QString &filepath = m_tabbar->fileAt(index);
bool bIsContains = false;

if (m_wrappers.contains(filepath)) {
EditWrapper *wrapper = m_wrappers.value(filepath);
wrapper->textEditor()->setFocus();

for (int i = 0;i < m_editorWidget->count();i++) {
if (m_editorWidget->widget(i) == wrapper) {
bIsContains = true;
}
}

if (!bIsContains) {
m_editorWidget->addWidget(wrapper);
}

m_editorWidget->setCurrentWidget(wrapper);
}

Expand Down

0 comments on commit 12d3e19

Please sign in to comment.