| 29 | } |
| 30 | |
| 31 | void ElaTabWidgetPrivate::onTabDragCreate(QMimeData* mimeData) |
| 32 | { |
| 33 | Q_Q(ElaTabWidget); |
| 34 | if (ElaDragMonitor::getInstance()->getIsInDrag()) |
| 35 | { |
| 36 | return; |
| 37 | } |
| 38 | ElaDragMonitor::getInstance()->setIsInDrag(true); |
| 39 | mimeData->setProperty("ElaTabWidgetObject", QVariant::fromValue(q)); |
| 40 | int index = q->currentIndex(); |
| 41 | QString tabText = q->tabText(index); |
| 42 | QIcon tabIcon = q->tabIcon(index); |
| 43 | QWidget* dragWidget = q->widget(index); |
| 44 | dragWidget->setProperty("TabIcon", q->tabIcon(index)); |
| 45 | dragWidget->setProperty("TabText", q->tabText(index)); |
| 46 | QWidget* originTabWidget = dragWidget->property("ElaOriginTabWidget").value<ElaTabWidget*>(); |
| 47 | if (!originTabWidget && !dragWidget->property("IsMetaWidget").toBool()) |
| 48 | { |
| 49 | dragWidget->setProperty("ElaOriginTabWidget", QVariant::fromValue<ElaTabWidget*>(q)); |
| 50 | originTabWidget = q; |
| 51 | } |
| 52 | mimeData->setProperty("DragWidget", QVariant::fromValue(dragWidget)); |
| 53 | ElaTabBar* tabBarObject = mimeData->property("ElaTabBarObject").value<ElaTabBar*>(); |
| 54 | QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(-1, -1), QPoint(-1, -1), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
| 55 | QApplication::sendEvent(tabBarObject, &releaseEvent); |
| 56 | if (!originTabWidget) |
| 57 | { |
| 58 | originTabWidget = dragWidget->property("ElaFloatParentWidget").value<QWidget*>(); |
| 59 | } |
| 60 | bool isFloatWidget = mimeData->property("IsFloatWidget").toBool(); |
| 61 | QSize tabSize = mimeData->property("TabSize").toSize(); |
| 62 | ElaCustomTabWidget* floatWidget = nullptr; |
| 63 | if (isFloatWidget) |
| 64 | { |
| 65 | floatWidget = dynamic_cast<ElaCustomTabWidget*>(q->window()); |
| 66 | if (floatWidget->windowHandle()) |
| 67 | { |
| 68 | floatWidget->windowHandle()->setFlag(Qt::WindowTransparentForInput, true); |
| 69 | } |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | floatWidget = new ElaCustomTabWidget(originTabWidget); |
| 74 | q->removeTab(index); |
| 75 | // 创建新窗口 |
| 76 | ElaTabBar* originCustomTabBar = tabBarObject; |
| 77 | if (originCustomTabBar && originCustomTabBar->objectName() == "ElaCustomTabBar") |
| 78 | { |
| 79 | originCustomTabBar->removeTab(index); |
| 80 | } |
| 81 | ElaTabBar* customTabBar = floatWidget->getCustomTabBar(); |
| 82 | customTabBar->setTabSize(tabSize); |
| 83 | floatWidget->getCustomTabWidget()->setFloatWidgetSize(_pFloatWidgetSize); |
| 84 | dragWidget->setProperty("CurrentCustomBar", QVariant::fromValue<ElaTabBar*>(customTabBar)); |
| 85 | floatWidget->addTab(dragWidget, tabIcon, tabText); |
| 86 | connect(customTabBar, &ElaTabBar::currentChanged, this, [=](int currentIndex) { |
| 87 | if (currentIndex < 0) |
| 88 | { |
nothing calls this directly
no test coverage detected