123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- #include "WindowAppMdiFrame.h"
- #include "WindowAppMdiSubContainer.h"
- #include "WindowAppGvlView.h"
- #include "WindowAppPouFrame.h"
- #include "WindowAppTaskView.h"
- #include "WindowAppTaskMonitorView.h"
- #include "WindowAppLogView.h"
- #include "WindowAppUiFrame.h"
- #include "WindowAppResourceManagerTree.h"
- #include "Pou.h"
- WindowAppMdiFrame::WindowAppMdiFrame()
- {
- // 初始化UI
- this->initUI();
- VPGlobal::Register(this);
- }
- WindowAppMdiFrame::~WindowAppMdiFrame()
- {
- }
- /// <summary>
- /// 初始化UI
- /// </summary>
- void WindowAppMdiFrame::initUI()
- {
- // 设置自身的风格
- // Tab方式
- this->setViewMode(QMdiArea::TabbedView);
- // 是否可以关闭子窗口
- this->setTabsClosable(true);
- // 采用梯形标题栏
- //this->setTabShape(QTabWidget::Triangular);
- // 设置标题栏的方向是在正上方
- this->setTabPosition(QTabWidget::North);
- // Tab是否可以拖动调整顺序
- this->setTabsMovable(true);
- }
- /// <summary>
- /// 根据类型添加对应类型的窗体
- /// </summary>
- /// <param name="strTitle"></param>
- /// <param name="viewType"></param>
- QWidget* WindowAppMdiFrame::addSubView(QString strTitle, SUBVIEW_TYPE viewType, bool bActive)
- {
- // 创建子视图的容器( SubWindow )
- WindowAppMdiSubContainer* subViewContainer = new WindowAppMdiSubContainer(strTitle);
- // 根据不同的类型创建对应视图
- QWidget* newView = nullptr;
- // QToolBar* viewToolBar = nullptr;
- if (viewType == SUBVIEW_TYPE::SUBVIEW_POU)
- {
- // 创建Pou视图
- newView = new WindowAppPouFrame(strTitle, subViewContainer);
- //// 2022-8-29 增加,注册PouFrame指针便于后续统一管理
- //g_pFrameManager->registerNewPouFrame(strTitle, (WindowAppPouFrame*)newView);
- }
- // 2022-2-16 Gvl视图有更多的参数,另外独立出来了
- //else if (viewType == SUBVIEW_TYPE::SUBVIEW_GVL)
- //{
- // // 创建Gvl视图
- // newView = new WindowAppGvlView(strTitle, subViewContainer);
- //}
- else if (viewType == SUBVIEW_TYPE::SUBVIEW_TASKMONITOR)
- {
- // 创建Task Monitor视图
- newView = new WindowAppTaskMonitorView(strTitle, subViewContainer);
- // 在VPGlobal中注册 Task Monitor
- VPGlobal::Register((WindowAppTaskMonitorView*)newView);
- }
- else if (viewType == SUBVIEW_TYPE::SUBVIEW_TASK)
- {
- // 创建Task视图
- newView = new WindowAppTaskView(strTitle, subViewContainer);
- }
- else if (viewType == SUBVIEW_TYPE::SUBVIEW_LOG)
- {
- // 创建Log视图
- newView = new WindowAppLogView(strTitle, subViewContainer);
- }
- else if (viewType == SUBVIEW_TYPE::SUBVIEW_HDW)
- {
- // 创建Hardware视图
- newView = new WindowAppPouFrame(strTitle, subViewContainer);
- }
- else if (viewType == SUBVIEW_TYPE::SUBVIEW_UI)
- {
- // 创建 UI 视图
- newView = new WindowAppUiFrame(strTitle, subViewContainer);
- //// 2022-8-29 增加,注册UiFrame指针便于后续统一管理
- //g_pFrameManager->registerNewUiFrame(strTitle, (WindowAppUiFrame*)newView);
- }
- else
- {
- // 报告一个错误
- Utility::VPCriticalMessageBox("Invalid WindowAppMdiSubContainer type:" + (short)viewType);
- return nullptr;
- }
- // 保存视图和子窗体容器信息
- m_containerToViews.insert(subViewContainer, newView);
- m_nameToContainers.insert(strTitle, subViewContainer);
- if (bActive)
- {
- // 激活此子窗口
- activeSubView(strTitle);
- // 设置子窗口的初始化大小
- AjustSubWindowGeometry(newView, subViewContainer);
- }
- return newView;
- }
- /// <summary>
- /// 2022-2-16 添加Gvl子窗体(由于GVL窗体参数增加,额外独立出来了)
- /// </summary>
- /// <param name="strTitle"></param>
- /// <param name="gvlType"></param>
- /// <param name="bActive"></param>
- /// <returns></returns>
- QWidget* WindowAppMdiFrame::addGvlSubView(QString strTitle, GVL_MODE gvlType, DllTool* pHdwTool, bool bActive /*= false*/)
- {
- // 创建子视图的容器( SubWindow )
- WindowAppMdiSubContainer* subViewContainer = new WindowAppMdiSubContainer(strTitle);
- // 创建视图
- QWidget* newView = new WindowAppGvlView(strTitle, gvlType, pHdwTool, subViewContainer);
- // 保存视图和子窗体容器信息
- m_containerToViews.insert(subViewContainer, newView);
- m_nameToContainers.insert(strTitle, subViewContainer);
- if (bActive)
- {
- // 激活此子窗口
- activeSubView(strTitle);
- // 设置子窗口的初始化大小
- AjustSubWindowGeometry(newView, subViewContainer);
- }
- return newView;
- }
- /// <summary>
- /// 激活对应的子窗体(按名称)
- /// </summary>
- /// <param name="strTitle"></param>
- void WindowAppMdiFrame::activeSubView(QString strTitle)
- {
- WindowAppMdiSubContainer* pSub = m_liveContainers[strTitle];
- if ( pSub==nullptr )
- {
- pSub = qobject_cast<WindowAppMdiSubContainer*>(this->addSubWindow(m_nameToContainers[strTitle]));
- if (pSub == nullptr)
- {
- return;
- }
- m_liveContainers.insert(strTitle, pSub);
- }
-
- // 激活窗体
- this->setActiveSubWindow(pSub);
-
- // 显示窗体
- pSub->showNormal();
- // 绑定关闭信号
- connect(
- pSub,
- &WindowAppMdiSubContainer::subWindowClosed,
- this,
- &WindowAppMdiFrame::onSubWindowClosed
- );
- // 绑定激活信号
- connect(
- pSub,
- &WindowAppMdiSubContainer::subWindowActivated,
- this,
- &WindowAppMdiFrame::onSubWindowActivated
- );
-
- // 调整内部的View尺寸
- QWidget* pSubView = this->findSubView(strTitle);
-
- AjustSubWindowGeometry(pSubView, pSub);
- vDebug() << pSub->m_strTitle;
- }
- /// <summary>
- /// 删除指定的子窗体(按名称)
- /// </summary>
- /// <param name="strTitle"></param>
- void WindowAppMdiFrame::deleteSubView(QString strTitle)
- {
- qDebug() << "[MDI] Delete sub view - " << strTitle;
- WindowAppMdiSubContainer* pContainer = m_nameToContainers[strTitle];
- if (pContainer == nullptr)
- {
- return;
- }
- // 从数据结构中清除此窗体
- m_containerToViews.remove(pContainer);
- m_nameToContainers.remove(strTitle);
- m_liveContainers.remove(strTitle);
- //g_pFrameManager->unregisterPouFrame(strTitle);
- //g_pFrameManager->unregisterUiFrame(strTitle);
- //// 关闭此窗体
- //if (this->isActiveWindow())
- //{
- // this->removeSubWindow(pContainer);
- //}
-
- // 删除窗体
- delete pContainer;
- pContainer = nullptr;
- // 如果还有剩余的子窗体的话,则激活
- if (m_liveContainers.size() > 0)
- {
- // 随便激活一个剩下的
- this->activateNextSubWindow();
- }
- }
- /// <summary>
- /// 删除所有子窗体
- /// </summary>
- void WindowAppMdiFrame::deleteAllSubViews()
- {
- QHashIterator<QString, WindowAppMdiSubContainer*> iter(m_nameToContainers);
- // 循环关闭所有窗体
- while (iter.hasNext())
- {
- QString strTitle = iter.next().key();
- if (strTitle != GROUP_NAME_HARDWARE
- && strTitle != GROUP_NAME_TASKMONITOR
- && strTitle != GROUP_NAME_LOGVIEW
- )
- {
- this->deleteSubView(strTitle);
- }
-
- }
- //m_containerToViews.clear();
- //m_nameToContainers.clear();
- //m_liveContainers.clear();
- }
- /// <summary>
- /// 根据名字查找对应的子窗体
- /// </summary>
- /// <param name="strNewName"></param>
- /// <returns></returns>
- QWidget* WindowAppMdiFrame::findSubView(QString strNewName)
- {
- QHashIterator<QString, WindowAppMdiSubContainer*> iter(m_nameToContainers);
- while (iter.hasNext())
- {
- if (iter.next().key() == strNewName)
- {
- return m_containerToViews[iter.value()];
- }
- }
- return nullptr;
- }
- /// <summary>
- /// 当子窗口关闭时触发
- /// </summary>
- /// <param name=""></param>
- void WindowAppMdiFrame::onSubWindowClosed(WindowAppMdiSubContainer* pSub)
- {
- // qDebug() << "WindowAppMdiFrame::onSubWindowClosed";
- this->removeSubWindow(m_liveContainers[pSub->m_strTitle]);
- m_liveContainers.remove(pSub->m_strTitle);
- }
- /// <summary>
- /// 2022-9-21,当子窗口激活时触发
- /// </summary>
- /// <param name=""></param>
- void WindowAppMdiFrame::onSubWindowActivated(WindowAppMdiSubContainer* pSub)
- {
- // 调用ResourceManager来进行对应的Toolbox切换
- g_pResourceManager->switchAppToolbox(pSub->m_strTitle);
- }
- //void WindowAppMdiFrame::setActiveSubWindow(QMdiSubWindow* window)
- //{
- // vDebug() << "setActiveSubWindow";
- //}
- /// <summary>
- /// 调整子窗体大小
- /// </summary>
- /// <param name="pView"></param>
- /// <param name="pContainer"></param>
- void WindowAppMdiFrame::AjustSubWindowGeometry(QWidget* pView, WindowAppMdiSubContainer* pContainer)
- {
- if (pView == nullptr)
- {
- return;
- }
- pView->resize(this->frameGeometry().size());
- pContainer->resize(this->frameGeometry().size());
- QApplication::sendEvent(pView , new QEvent(QResizeEvent::Resize));
-
- // qDebug() << "Resize " << pView << " + " << pContainer;
- }
- /// <summary>
- /// 自动缩放
- /// </summary>
- /// <param name="resizeEvent"></param>
- void WindowAppMdiFrame::resizeEvent(QResizeEvent* resizeEvent)
- {
- Q_UNUSED(resizeEvent);
- // qDebug() << "WindowAppMdiFrame::resizeEvent";
- // 调整所有窗口大小
- QHashIterator<WindowAppMdiSubContainer* ,QWidget*> iter(m_containerToViews);
- while (iter.hasNext())
- {
- this->AjustSubWindowGeometry(iter.value(), iter.next().key());
- }
- }
|