fix process exit
This commit is contained in:
parent
343617cf43
commit
023348c7ef
|
|
@ -29,11 +29,9 @@ protected:
|
|||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
private:
|
||||
void setupUI();
|
||||
|
||||
void centerWindowOnce();
|
||||
private:
|
||||
QPoint m_dragStartPosition;
|
||||
QWidget *m_parentWindow;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
#include <QStyle>
|
||||
#include <QScreen>
|
||||
#include <QGuiApplication>
|
||||
|
||||
#include <QTimer>
|
||||
#include <QWindow>
|
||||
|
||||
TitleBar::TitleBar(QWidget *parent,bool bClose,bool bMaxMin)
|
||||
: QWidget(parent)
|
||||
|
|
@ -42,8 +43,10 @@ TitleBar::TitleBar(QWidget *parent,bool bClose,bool bMaxMin)
|
|||
|
||||
setStyleSheet(style);
|
||||
|
||||
// ✅ 每次 show 都居中
|
||||
if (m_parentWindow) {
|
||||
m_parentWindow->installEventFilter(this);
|
||||
connect(m_parentWindow, &QWidget::show,
|
||||
this, &TitleBar::centerWindowOnce);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +96,50 @@ void TitleBar::setupUI()
|
|||
}
|
||||
}
|
||||
|
||||
void TitleBar::centerWindowOnce()
|
||||
{
|
||||
if (!m_parentWindow)
|
||||
return;
|
||||
|
||||
if (m_parentWindow->isMaximized() ||
|
||||
m_parentWindow->isFullScreen())
|
||||
return;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QTimer::singleShot(0, this, [this] {
|
||||
QScreen *screen = m_parentWindow->screen();
|
||||
if (!screen)
|
||||
screen = QGuiApplication::primaryScreen();
|
||||
if (!screen)
|
||||
return;
|
||||
|
||||
QRect screenRect = screen->availableGeometry();
|
||||
QRect windowRect = m_parentWindow->geometry();
|
||||
|
||||
m_parentWindow->move(
|
||||
screenRect.center() - windowRect.center()
|
||||
);
|
||||
});
|
||||
|
||||
#elif defined(Q_OS_MACOS)
|
||||
QTimer::singleShot(0, this, [this] {
|
||||
QScreen *screen = m_parentWindow->screen();
|
||||
if (!screen)
|
||||
screen = QGuiApplication::primaryScreen();
|
||||
if (!screen)
|
||||
return;
|
||||
|
||||
QRect screenRect = screen->availableGeometry();
|
||||
QRect windowRect = m_parentWindow->geometry();
|
||||
|
||||
m_parentWindow->move(
|
||||
screenRect.center() - windowRect.center()
|
||||
);
|
||||
});
|
||||
#endif
|
||||
// ✅ Linux:什么都不做,交给窗口管理器
|
||||
}
|
||||
|
||||
void TitleBar::setTitle(const QString &title)
|
||||
{
|
||||
m_titleLabel->setText(title);
|
||||
|
|
@ -123,17 +170,37 @@ void TitleBar::updateMaximizeButton()
|
|||
void TitleBar::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_dragStartPosition = event->globalPosition().toPoint() - m_parentWindow->frameGeometry().topLeft();
|
||||
m_dragStartPosition = event->pos();
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void TitleBar::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
m_parentWindow->move(event->globalPosition().toPoint() - m_dragStartPosition);
|
||||
event->accept();
|
||||
if (!(event->buttons() & Qt::LeftButton))
|
||||
return;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
m_parentWindow->move(
|
||||
m_parentWindow->pos() +
|
||||
(event->pos() - m_dragStartPosition)
|
||||
);
|
||||
|
||||
#elif defined(Q_OS_MACOS)
|
||||
// ✅ macOS:Qt 原生拖拽
|
||||
m_parentWindow->move(
|
||||
m_parentWindow->pos() +
|
||||
(event->pos() - m_dragStartPosition)
|
||||
);
|
||||
|
||||
#elif defined(Q_OS_LINUX)
|
||||
QWindow *win = m_parentWindow->windowHandle();
|
||||
if (win && win->handle()) {
|
||||
win->startSystemMove();
|
||||
}
|
||||
#endif
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void TitleBar::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
|
|
@ -142,29 +209,3 @@ void TitleBar::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
emit maximizeClicked();
|
||||
}
|
||||
}
|
||||
|
||||
bool TitleBar::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == m_parentWindow && event->type() == QEvent::Show) {
|
||||
|
||||
// 防止最大化/全屏时干扰
|
||||
if (m_parentWindow->isMaximized() ||
|
||||
m_parentWindow->isFullScreen()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
if (!screen)
|
||||
return false;
|
||||
|
||||
QRect screenRect = screen->availableGeometry();
|
||||
QRect windowRect = m_parentWindow->geometry(); // ✅ 正确
|
||||
|
||||
int x = screenRect.x() + (screenRect.width() - windowRect.width()) / 2;
|
||||
int y = screenRect.y() + (screenRect.height() - windowRect.height()) / 2;
|
||||
|
||||
m_parentWindow->move(x, y);
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ signals:
|
|||
void prepareUpdateTopology(QList<HierarchyItem>,bool refresh,bool showFull); //更新层级数 refresh:刷新标志,showFull:显示全部层级
|
||||
|
||||
void updateMonitorTopology(QList<QUuid>);
|
||||
void pannelSelected(QString sPanel,int nType); //界面选择信号,名称,类型(0:editor)
|
||||
public slots:
|
||||
void onSignal_addDrawingPanel(PowerEntity* p,DiagramMode = DM_edit,QString parent = QString()); //parent:派生运行时的page
|
||||
void onSignal_addGraphicsItem(ModelStateInfo&);
|
||||
|
|
@ -68,6 +69,7 @@ public slots:
|
|||
void runPage(const QString); //运行时
|
||||
void onSignal_runPage();
|
||||
void onSignal_deletePage();
|
||||
void onSubWindowActivated(QMdiSubWindow *subWindow); //子窗口激活事件
|
||||
|
||||
void onSignal_activatePage(const QString& name);
|
||||
void onSignal_panelDelete(const QString& name,int nType); //type:0editorPanel,1drawPanel
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ public:
|
|||
|
||||
void prepareSaveEditor(); //准备保存
|
||||
void loadBaseSetting(QUuid);
|
||||
void activePreview(); //激活预览
|
||||
public slots:
|
||||
void onWidthChanged(int width);
|
||||
void onContainerSizeChanged(EditContainerItem*); //容器大小改变时调整内部大小
|
||||
|
|
|
|||
|
|
@ -180,6 +180,8 @@ void DiagramCavas::initial()
|
|||
|
||||
QQuickDetailsViewManager::Get()->registerPropertyTypeCustomization<DataSourceType, PropertyTypeCustomization_DataSourceType>();
|
||||
BaseTypeManager::getInstance()->initial();
|
||||
|
||||
connect(this, &QMdiArea::subWindowActivated,this, &DiagramCavas::onSubWindowActivated);
|
||||
}
|
||||
|
||||
void DiagramCavas::onSignal_addDrawingPanel(PowerEntity* pItem,DiagramMode mode,QString parent)
|
||||
|
|
@ -190,6 +192,7 @@ void DiagramCavas::onSignal_addDrawingPanel(PowerEntity* pItem,DiagramMode mode,
|
|||
pPanel->setPageName(_curPage);
|
||||
pPanel->setWindowTitle(_curPage);
|
||||
QMdiSubWindow* pSub = this->addSubWindow(pPanel);
|
||||
pSub->showMaximized();
|
||||
m_mapDrawPanel.insert(_curPage,qMakePair(pPanel,pSub));
|
||||
pPanel->show();
|
||||
|
||||
|
|
@ -209,6 +212,7 @@ void DiagramCavas::onSignal_addDrawingPanel(PowerEntity* pItem,DiagramMode mode,
|
|||
pPanel->setWindowTitle(_curPage);
|
||||
pPanel->setParentPage(parent);
|
||||
QMdiSubWindow* pSub = this->addSubWindow(pPanel);
|
||||
pSub->showMaximized();
|
||||
m_mapMonitorPanel.insert(_curPage,qMakePair(pPanel,pSub));
|
||||
pPanel->show();
|
||||
|
||||
|
|
@ -318,6 +322,8 @@ void DiagramCavas::onSignal_loadEdit(const QString& sProject,QUuid uid)
|
|||
{
|
||||
//todo:新建或加载时删除old
|
||||
m_mapEditPanel[sProject].first->show();
|
||||
m_mapEditPanel[sProject].first->activePreview();
|
||||
setActiveSubWindow(m_mapEditPanel[sProject].second);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -360,6 +366,23 @@ void DiagramCavas::onSignal_deletePage()
|
|||
|
||||
}
|
||||
|
||||
void DiagramCavas::onSubWindowActivated(QMdiSubWindow *subWindow)
|
||||
{
|
||||
QString sObj;
|
||||
// 反向查找
|
||||
for (auto it = m_mapEditPanel.constBegin(); it != m_mapEditPanel.constEnd(); ++it) {
|
||||
if (it.value().second == subWindow) {
|
||||
// 找到匹配的窗口
|
||||
sObj = it.key();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!sObj.isEmpty()){
|
||||
m_mapEditPanel[sObj].first->activePreview();
|
||||
emit pannelSelected(sObj,0);
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramCavas::onSignal_activatePage(const QString& name)
|
||||
{
|
||||
_curPage = name;
|
||||
|
|
@ -573,6 +596,13 @@ void DiagramCavas::resizeEvent(QResizeEvent* event)
|
|||
{
|
||||
if(_cornerButton)
|
||||
_cornerButton->positionAtCorner();
|
||||
QMdiArea::resizeEvent(event);
|
||||
// 获取 MDI 客户区(减去可能的滚动条/边距)
|
||||
QRect clientRect = viewport()->rect();
|
||||
|
||||
foreach (QMdiSubWindow *window, subWindowList()) {
|
||||
window->setGeometry(clientRect);
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramCavas::onTargetSelected(QObject* obj)
|
||||
|
|
@ -637,6 +667,7 @@ EditPanel* DiagramCavas::onSignal_addEditPanel(QString sName)
|
|||
}
|
||||
|
||||
QMdiSubWindow* pSub = this->addSubWindow(pPanel);
|
||||
pSub->showMaximized();
|
||||
m_mapEditPanel.insert(_curPage,qMakePair(pPanel,pSub));
|
||||
pPanel->show();
|
||||
return pPanel;
|
||||
|
|
|
|||
|
|
@ -463,6 +463,14 @@ void EditPanel::loadBaseSetting(QUuid uid)
|
|||
}
|
||||
}
|
||||
|
||||
void EditPanel::activePreview()
|
||||
{
|
||||
if(_pPreview){
|
||||
_pPreview->raise();
|
||||
_pPreview->activateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
void EditPanel::performCleanup() {
|
||||
// 清理模型
|
||||
if (_pModel) {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ public slots:
|
|||
void onNewEditorCreated(const QString&,QUuid);
|
||||
void onEditorLoaded(const QString&,QUuid);
|
||||
void onEditorSaved(const QString& strPro,const QString& autor,QUuid uid,QString sTime);
|
||||
void onPanelActive(QString,int); //面板激活反馈 名称,类型 0editor
|
||||
|
||||
void onNewEditorClicked();
|
||||
void onOpenEditorClicked();
|
||||
|
|
@ -54,6 +55,7 @@ private:
|
|||
private:
|
||||
QString generateName();
|
||||
int getItemLevel(QTreeWidgetItem *item);
|
||||
void searchAndSelect(QTreeWidgetItem *item, const QString &target);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -87,5 +87,6 @@ private:
|
|||
BaseDockWidget* m_pPropertyEditorDock;
|
||||
QDetailsView* m_pPropertiesEditorView;
|
||||
QAction* _pActMonitor;
|
||||
bool _released = false;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ CreateEditor::CreateEditor(QWidget *parent,DiagramView* p)
|
|||
setWindowModality(Qt::ApplicationModal);
|
||||
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
||||
initial();
|
||||
|
||||
QScreen *screen = this->screen() ? this->screen()
|
||||
: QGuiApplication::primaryScreen();
|
||||
move(screen->availableGeometry().center() - rect().center()); //linux
|
||||
}
|
||||
|
||||
CreateEditor::~CreateEditor()
|
||||
|
|
|
|||
|
|
@ -352,6 +352,17 @@ void DiagramView::onEditorSaved(const QString& strPro,const QString& autor,QUuid
|
|||
}
|
||||
}
|
||||
|
||||
void DiagramView::onPanelActive(QString target,int nType)
|
||||
{
|
||||
if(nType == 0){
|
||||
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); ++i)
|
||||
{
|
||||
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(i);
|
||||
searchAndSelect(item, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramView::onNewEditorClicked()
|
||||
{
|
||||
emit createProject();
|
||||
|
|
@ -389,3 +400,24 @@ int DiagramView::getItemLevel(QTreeWidgetItem *item) {
|
|||
}
|
||||
return level + 1; // 顶级节点为1级
|
||||
}
|
||||
|
||||
// 递归查找并选中
|
||||
void DiagramView::searchAndSelect(QTreeWidgetItem *item, const QString &target)
|
||||
{
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
// 判断当前节点 text(第 0 列)
|
||||
if (item->text(0) == target)
|
||||
{
|
||||
item->setSelected(true); // 选中
|
||||
item->setExpanded(true); // 可选:展开父节点
|
||||
item->treeWidget()->setCurrentItem(item); // 设为当前项
|
||||
}
|
||||
|
||||
// 递归子节点
|
||||
for (int i = 0; i < item->childCount(); ++i)
|
||||
{
|
||||
searchAndSelect(item->child(i), target);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,10 +61,12 @@ CMainWindow::~CMainWindow()
|
|||
delete ui;
|
||||
//if(m_pElectricElementsBox)
|
||||
//delete m_pElectricElementsBox;
|
||||
if(m_pPropertiesEditorView){
|
||||
auto pView = m_pPropertiesEditorView->getQuickDetailsView();
|
||||
delete pView;
|
||||
delete m_pPropertiesEditorView;
|
||||
if(!_released){
|
||||
if(m_pPropertiesEditorView){
|
||||
auto pView = m_pPropertiesEditorView->getQuickDetailsView();
|
||||
delete pView;
|
||||
delete m_pPropertiesEditorView;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,9 +76,12 @@ void CMainWindow::closeEvent(QCloseEvent* event)
|
|||
// Delete dock manager here to delete all floating widgets. This ensures
|
||||
// that all top level windows of the dock manager are properly closed
|
||||
QMainWindow::closeEvent(event);
|
||||
QTimer::singleShot(500, this, [this]() { //临时处理
|
||||
::exit(0);
|
||||
});
|
||||
if(m_pPropertiesEditorView){
|
||||
auto pView = m_pPropertiesEditorView->getQuickDetailsView();
|
||||
delete pView;
|
||||
delete m_pPropertiesEditorView;
|
||||
_released = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CMainWindow::changeEvent(QEvent* event)
|
||||
|
|
@ -189,12 +194,14 @@ void CMainWindow::initializeAction()
|
|||
connect(m_pDiagramView,&DiagramView::diagramDelete,m_pDiagramCavas,&DiagramCavas::onSignal_deleteDiagram);
|
||||
connect(m_pDiagramView,&DiagramView::diagramSelected,m_pDiagramCavas,&DiagramCavas::onSignal_selectDiagram);
|
||||
connect(m_pDiagramView,&DiagramView::createProject,this,&CMainWindow::onAction_createEditor);
|
||||
connect(m_pDiagramCavas,&DiagramCavas::pannelSelected,m_pDiagramView,&DiagramView::onPanelActive);
|
||||
connect(m_pDiagramCavas,&DiagramCavas::prepareUpdateItems,m_pMonitorItemsDlg,&MonitorItemsDlg::onUpdateItems);
|
||||
connect(m_pDiagramCavas,&DiagramCavas::prepareSelectItems,m_pMonitorItemsDlg,&MonitorItemsDlg::onSelectItems);
|
||||
connect(m_pDiagramCavas,&DiagramCavas::updateMonitorList,m_pMonitorPagesDlg,&MonitorPagesDlg::onMonitorCreated);
|
||||
connect(m_pDiagramCavas,&DiagramCavas::createdMonitorItems,m_pMonitorItemsDlg,&MonitorItemsDlg::onMonitorCreated);
|
||||
connect(m_pDiagramCavas,&DiagramCavas::updateMonitorTopology,m_pTopologyView,&TopologyView::onMonitorUpdate);
|
||||
|
||||
|
||||
connect(m_pMonitorItemsDlg,&MonitorItemsDlg::generateMonitor,m_pDiagramCavas,&DiagramCavas::onSignal_generate);
|
||||
connect(m_pMonitorPagesDlg,&MonitorPagesDlg::monitorSelected,m_pDiagramCavas,&DiagramCavas::onSignal_monitorSelected);
|
||||
connect(m_pMonitorPagesDlg,&MonitorPagesDlg::prepareSaveMonitor,m_pDiagramCavas,&DiagramCavas::onSignal_saveMonitor);
|
||||
|
|
|
|||
Loading…
Reference in New Issue