2025-10-29 17:23:30 +08:00
|
|
|
|
//customtabwidget.cpp
|
|
|
|
|
|
|
|
|
|
|
|
#include "customtabwidget.h"
|
|
|
|
|
|
#include <QStackedWidget>
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
|
#include <QMimeData>
|
|
|
|
|
|
#include <QDrag>
|
|
|
|
|
|
#include <QFrame>
|
|
|
|
|
|
#include <QDropEvent>
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
#include "customtabbar.h"
|
2026-01-23 18:20:18 +08:00
|
|
|
|
#include "PropertyWidget.h"
|
2026-05-21 14:01:46 +08:00
|
|
|
|
#include "mainwindowsplitter.h"
|
2026-05-26 14:29:02 +08:00
|
|
|
|
#include "CallManage.h"
|
2025-10-29 17:23:30 +08:00
|
|
|
|
|
|
|
|
|
|
CustomTabWidget::CustomTabWidget(QWidget *parent)
|
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pTabBar = new CustomTabBar(this);
|
|
|
|
|
|
QHBoxLayout *pHLayout = new QHBoxLayout;
|
|
|
|
|
|
pHLayout->addWidget(m_pTabBar);
|
|
|
|
|
|
pHLayout->addStretch();
|
|
|
|
|
|
m_pStackedWidget = new QStackedWidget(this);
|
|
|
|
|
|
QVBoxLayout *pVLayout = new QVBoxLayout(this);
|
|
|
|
|
|
pVLayout->addLayout(pHLayout);
|
|
|
|
|
|
pVLayout->addWidget(m_pStackedWidget);
|
|
|
|
|
|
pVLayout->setStretch(1, 1);
|
|
|
|
|
|
pVLayout->setMargin(0);
|
|
|
|
|
|
pVLayout->setSpacing(0);
|
|
|
|
|
|
connect(m_pTabBar, SIGNAL(currentChanged(int)), this, SLOT(setCurrentIndex(int)));
|
|
|
|
|
|
setAcceptDrops(true);
|
|
|
|
|
|
m_pStackedWidget->setStyleSheet("QStackedWidget{border: 1px solid #000000;}");
|
|
|
|
|
|
|
|
|
|
|
|
//关闭tab时,信号槽触发的函数
|
|
|
|
|
|
connect(m_pTabBar, SIGNAL(tabCloseRequested(int)),this,SLOT(slot_tabClose(int)));
|
2026-05-26 14:29:02 +08:00
|
|
|
|
//关闭当前tab页,重新打开新模板
|
2026-06-02 17:31:33 +08:00
|
|
|
|
connect(CallManage::getInstance(), SIGNAL(sig_tabCloseCurrent(QString, QString, bool)), this, SLOT(slot_tabCloseCurrent(QString, QString, bool)));
|
2026-05-26 14:29:02 +08:00
|
|
|
|
|
2025-10-29 17:23:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CustomTabWidget::~CustomTabWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::addTab(QWidget *widget, const QString &strTab)
|
|
|
|
|
|
{
|
2026-04-22 17:28:35 +08:00
|
|
|
|
int iIndex = -1;
|
|
|
|
|
|
for (int i = 0; i < m_pStackedWidget->count(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_pStackedWidget->widget(i) == widget)
|
|
|
|
|
|
{
|
|
|
|
|
|
iIndex = i;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (iIndex < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
iIndex = m_pTabBar->addTab(strTab);
|
|
|
|
|
|
m_pStackedWidget->addWidget(widget);
|
|
|
|
|
|
widget->setAcceptDrops(true);
|
|
|
|
|
|
}
|
2025-10-31 17:56:50 +08:00
|
|
|
|
//
|
|
|
|
|
|
m_pTabBar->setCurrentIndex(iIndex);
|
2025-10-29 17:23:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::addTab(QWidget *page, const QIcon &icon, const QString &label)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pTabBar->addTab(icon, label);
|
|
|
|
|
|
m_pStackedWidget->addWidget(page);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::addTabs(CustomTabWidget *pOtherTab)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < pOtherTab->count(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
addTab(pOtherTab->tabWidget(0), pOtherTab->tabText(i));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CustomTabWidget::count() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pTabBar->count();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CustomTabWidget::currentIndex() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pTabBar->currentIndex();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget * CustomTabWidget::currentWidget() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pStackedWidget->currentWidget();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CustomTabWidget::insertTab(int index, QWidget *page, const QString &label)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pTabBar->insertTab(index, label);
|
|
|
|
|
|
return m_pStackedWidget->insertWidget(index, page);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CustomTabWidget::insertTab(int index, QWidget *page, const QIcon &icon, const QString &label)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pTabBar->insertTab(index, icon, label);
|
|
|
|
|
|
return m_pStackedWidget->insertWidget(index, page);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::removeTab(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pTabBar->removeTab(index);
|
2026-05-27 09:52:53 +08:00
|
|
|
|
|
|
|
|
|
|
QWidget* pWgt = m_pStackedWidget->widget(index);
|
|
|
|
|
|
m_pStackedWidget->removeWidget(pWgt); //widget is not deleted but simply removed from the stacked layout, causing it to be hidden.
|
|
|
|
|
|
pWgt->deleteLater();
|
2025-10-29 17:23:30 +08:00
|
|
|
|
if (m_pTabBar->count() == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
emit tabIsEmpty();
|
|
|
|
|
|
if (m_bAutoDelete)
|
|
|
|
|
|
{
|
|
|
|
|
|
hide();
|
|
|
|
|
|
deleteLater();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString CustomTabWidget::tabText(int index) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pTabBar->tabText(index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget * CustomTabWidget::tabWidget(int index) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pStackedWidget->widget(index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::setAutoHideTabBar(bool bHide)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_bAutoHideBar = bHide;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::setCurrentIndex(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pStackedWidget->setCurrentIndex(index);
|
|
|
|
|
|
emit currentTabChanged(m_pTabBar->tabText(index));
|
2026-01-23 18:20:18 +08:00
|
|
|
|
|
|
|
|
|
|
//属性清空
|
|
|
|
|
|
PropertyService()->InitCurrentViewInfo();
|
2026-05-21 14:01:46 +08:00
|
|
|
|
|
|
|
|
|
|
QWidget *selectWidget = tabWidget(index);
|
|
|
|
|
|
if (selectWidget == NULL)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
QString objectName = selectWidget->objectName();
|
|
|
|
|
|
if(objectName == "MainWindowSplitter")
|
|
|
|
|
|
{
|
|
|
|
|
|
MainWindowSplitter *tmpWindow = (MainWindowSplitter*)selectWidget;
|
|
|
|
|
|
tmpWindow->getMainWindowCurve()->SetNo();
|
|
|
|
|
|
}
|
2025-10-29 17:23:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::setAutoDelete(bool bAuto)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_bAutoDelete = bAuto;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::mousePressEvent(QMouseEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget::mousePressEvent(event);
|
|
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
|
|
m_dragStartPos = event->pos();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget::mouseMoveEvent(event);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::paintEvent(QPaintEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_bAutoHideBar)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pTabBar->setVisible(m_pTabBar->count() > 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CustomTabWidget::dropEvent(QDropEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (event->mimeData()->hasFormat("application/itemdata"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QByteArray itemData = event->mimeData()->data("application/itemdata");
|
|
|
|
|
|
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
|
|
|
|
|
|
long long llPtrParent;
|
|
|
|
|
|
QString strTab;
|
|
|
|
|
|
long long llPtrChild;
|
|
|
|
|
|
int nTabIndex;
|
|
|
|
|
|
dataStream >> llPtrParent >> strTab >> llPtrChild >> nTabIndex;
|
|
|
|
|
|
CustomTabWidget *tabWidgetFrom = (CustomTabWidget *)llPtrParent;
|
|
|
|
|
|
QWidget *child = (QWidget *)llPtrChild;
|
|
|
|
|
|
if (child)
|
|
|
|
|
|
{
|
|
|
|
|
|
addTab(child, strTab);
|
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
event->ignore();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//关闭
|
|
|
|
|
|
void CustomTabWidget::slot_tabClose(int index)
|
|
|
|
|
|
{
|
2026-03-31 15:44:15 +08:00
|
|
|
|
QWidget *selectWidget = tabWidget(index);
|
2026-04-13 21:33:20 +08:00
|
|
|
|
if (selectWidget == NULL)
|
|
|
|
|
|
return;
|
2026-03-31 15:44:15 +08:00
|
|
|
|
|
|
|
|
|
|
QString objectName = selectWidget->objectName();
|
|
|
|
|
|
if(objectName == "MainWindowSplitter")
|
|
|
|
|
|
{
|
|
|
|
|
|
int flag = QMessageBox::warning(NULL,"提示",QString("图文件尚未保存,您确信关闭当前窗口?"),QMessageBox::Yes,QMessageBox::No);
|
|
|
|
|
|
if(flag!=QMessageBox::Yes) return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//移除
|
2025-10-29 17:23:30 +08:00
|
|
|
|
removeTab(index);
|
2026-01-23 18:20:18 +08:00
|
|
|
|
|
|
|
|
|
|
//属性清空
|
|
|
|
|
|
PropertyService()->InitCurrentViewInfo();
|
2025-10-29 17:23:30 +08:00
|
|
|
|
}
|
2026-05-26 14:29:02 +08:00
|
|
|
|
|
|
|
|
|
|
//关闭
|
2026-06-02 17:31:33 +08:00
|
|
|
|
void CustomTabWidget::slot_tabCloseCurrent(QString fileFull, QString fileName, bool bMultiProject)
|
2026-05-26 14:29:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
QWidget *selectWidget = m_pStackedWidget->currentWidget();
|
|
|
|
|
|
if (selectWidget == NULL)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
QString objectName = selectWidget->objectName();
|
|
|
|
|
|
if(objectName == "MainWindowSplitter")
|
|
|
|
|
|
{
|
|
|
|
|
|
int flag = QMessageBox::warning(NULL,"提示",QString("应用模板后当前图文件将废弃,确定应用模板?"),QMessageBox::Yes,QMessageBox::No);
|
|
|
|
|
|
if(flag!=QMessageBox::Yes) return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//移除
|
|
|
|
|
|
int index = m_pTabBar->currentIndex();
|
|
|
|
|
|
removeTab(index);
|
|
|
|
|
|
|
|
|
|
|
|
//属性清空
|
|
|
|
|
|
PropertyService()->InitCurrentViewInfo();
|
|
|
|
|
|
|
|
|
|
|
|
//重新打开新模板
|
2026-06-02 17:31:33 +08:00
|
|
|
|
emit CallManage::getInstance()->sig_ReOpen(fileFull, fileName, bMultiProject);
|
2026-05-26 14:29:02 +08:00
|
|
|
|
}
|