mainwindow.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3. #include <QFile>
  4. #include <QTextEdit>
  5. #include <QAbstractButton>
  6. #include <QFileDialog>
  7. #include "SARibbonBar.h"
  8. #include "SARibbonCategory.h"
  9. #include <QPushButton>
  10. #include <QMessageBox>
  11. #include "SARibbonPannel.h"
  12. #include "SARibbonToolButton.h"
  13. #include <QAction>
  14. #include <QMenu>
  15. #include <QStatusBar>
  16. #include <QDebug>
  17. #include <QElapsedTimer>
  18. #include <QRadioButton>
  19. #include <QButtonGroup>
  20. #include <QSpinBox>
  21. #include <QSplitter>
  22. #include <QLineEdit>
  23. #include <QCalendarWidget>
  24. #include <QXmlStreamWriter>
  25. #include <QTextStream>
  26. #include <QFontComboBox>
  27. #include <QLabel>
  28. #include "SARibbonMenu.h"
  29. #include "SARibbonComboBox.h"
  30. #include "SARibbonLineEdit.h"
  31. #include "SARibbonGallery.h"
  32. #include "SARibbonCheckBox.h"
  33. #include "SARibbonQuickAccessBar.h"
  34. #include "SARibbonButtonGroupWidget.h"
  35. #include "SARibbonApplicationButton.h"
  36. #include "SARibbonCustomizeWidget.h"
  37. #include "SARibbonElementManager.h"
  38. #include "SARibbonCustomizeDialog.h"
  39. #include "SARibbonColorToolButton.h"
  40. #include "SAFramelessHelper.h"
  41. #include "colorWidgets/SAColorPaletteGridWidget.h"
  42. #include "colorWidgets/SAColorGridWidget.h"
  43. #include <QDockWidget>
  44. #define PRINT_COST_START() \
  45. QElapsedTimer __TMP_COST; \
  46. __TMP_COST.start(); \
  47. int __TMP_LASTTIMES = 0
  48. #define PRINT_COST(STR) \
  49. do { \
  50. int ___TMP_INT = __TMP_COST.elapsed(); \
  51. qDebug() << STR << " cost " << ___TMP_INT - __TMP_LASTTIMES << " ms (" << ___TMP_INT << ")"; \
  52. m_edit->append(QString("%1 cost %2 ms(%3)").arg(STR).arg(___TMP_INT - __TMP_LASTTIMES).arg(___TMP_INT)); \
  53. __TMP_LASTTIMES = ___TMP_INT; \
  54. } while (0)
  55. MainWindow::MainWindow(QWidget* par) : SARibbonMainWindow(par), m_customizeWidget(nullptr)
  56. {
  57. PRINT_COST_START();
  58. mModelPage = new ModelPage();
  59. //菜单栏
  60. mTreeList = new QDockWidget("菜单",this);
  61. mTreeList->setFeatures(QDockWidget::NoDockWidgetFeatures);
  62. addDockWidget(Qt::LeftDockWidgetArea,mTreeList);
  63. initTree();
  64. mTreeList->setWidget(mTree);
  65. //主界面
  66. mCent = new QDockWidget("主界面",this);
  67. addDockWidget(Qt::RightDockWidgetArea,mCent);
  68. mCent->setFeatures(QDockWidget::NoDockWidgetFeatures);
  69. setCorner(Qt::BottomLeftCorner,Qt::LeftDockWidgetArea);
  70. initStack();
  71. mCent->setWidget(mStack);
  72. setCentralWidget(mCent);
  73. //控制台
  74. mConsole = new QDockWidget("控制台",this);
  75. addDockWidget(Qt::BottomDockWidgetArea,mConsole);
  76. mConsole->setAllowedAreas(Qt::BottomDockWidgetArea);
  77. SAFramelessHelper* helper = framelessHelper();
  78. helper->setRubberBandOnResize(false);
  79. m_edit = new QTextEdit(this);
  80. mConsole->setWidget(m_edit);
  81. setStatusBar(new QStatusBar());
  82. SARibbonBar* ribbon = ribbonBar();
  83. //通过setContentsMargins设置ribbon四周的间距
  84. ribbon->setContentsMargins(5, 0, 5,0);
  85. //设置applicationButton
  86. PRINT_COST("setCentralWidget & setWindowTitle");
  87. ribbon->applicationButton()->setText(("File"));
  88. ribbon->applicationButton()->hide();
  89. //添加主标签页 - 通过addCategoryPage工厂函数添加
  90. SARibbonCategory* categoryFile = ribbon->addCategoryPage(tr("文件(F)"));
  91. categoryFile->setObjectName(("categoryFile"));
  92. createCategoryFile(categoryFile);
  93. PRINT_COST("new main page");
  94. //添加显示标签页 - 直接new SARibbonCategory添加
  95. SARibbonCategory* categoryDisplay = new SARibbonCategory();
  96. categoryDisplay->setCategoryName(tr("显示(S)"));
  97. categoryDisplay->setObjectName(("categoryDisplay"));
  98. createCategoryDisplay(categoryDisplay);
  99. ribbon->addCategoryPage(categoryDisplay);
  100. PRINT_COST("add categoryDisplay page");
  101. //添加数据标签页
  102. SARibbonCategory* categoryData = new SARibbonCategory();
  103. categoryData->setCategoryName(("数据(D)"));
  104. categoryData->setObjectName(("categoryDelete"));
  105. ribbon->addCategoryPage(categoryData);
  106. createCategoryData(categoryData);
  107. PRINT_COST("add category categoryData page");
  108. //添加导入标签页
  109. SARibbonCategory* categoryGrid = new SARibbonCategory();
  110. categoryGrid->setCategoryName(("网格(G)"));
  111. categoryGrid->setObjectName(("categoryGrid"));
  112. ribbon->addCategoryPage(categoryGrid);
  113. createCategoryGrid(categoryGrid);
  114. PRINT_COST("add category categoryGrid page");
  115. //添加帮助标签页
  116. SARibbonCategory* categoryHelp = new SARibbonCategory();
  117. categoryHelp->setCategoryName(("帮助(H)"));
  118. categoryHelp->setObjectName(("categoryHelp"));
  119. ribbon->addCategoryPage(categoryHelp);
  120. createCategoryHelp(categoryHelp);
  121. PRINT_COST("add category help page");
  122. SARibbonQuickAccessBar* quickAccessBar = ribbon->quickAccessBar();
  123. createQuickAccessBar(quickAccessBar);
  124. PRINT_COST("add quick access bar");
  125. SARibbonButtonGroupWidget* rightBar = ribbon->rightButtonGroup();
  126. createRightButtonGroup(rightBar);
  127. PRINT_COST("add right bar");
  128. setMinimumWidth(800);
  129. showMaximized();
  130. ribbonBar()->setRibbonStyle(SARibbonBar::WpsLiteStyleTwoRow);
  131. }
  132. void MainWindow::initTree()
  133. {
  134. mTree = new QTreeWidget();
  135. mTree->setHeaderHidden(true);
  136. QTreeWidgetItem* modelItem = new QTreeWidgetItem(mTree);
  137. modelItem->setText(0,"模型");
  138. mTree->addTopLevelItem(modelItem);
  139. QTreeWidgetItem* gridItem = new QTreeWidgetItem(mTree);
  140. gridItem->setText(0,"网格");
  141. mTree->addTopLevelItem(gridItem);
  142. QTreeWidgetItem* CfdItem = new QTreeWidgetItem(mTree);
  143. CfdItem->setText(0,"CFD计算");
  144. mTree->addTopLevelItem(CfdItem);
  145. QTreeWidgetItem* CfdSetItem = new QTreeWidgetItem(CfdItem);
  146. CfdSetItem->setText(0,"设置");
  147. QTreeWidgetItem* CfdCalcItem = new QTreeWidgetItem(CfdItem);
  148. CfdCalcItem->setText(0,"计算");
  149. QTreeWidgetItem* CfdResultItem = new QTreeWidgetItem(CfdItem);
  150. CfdResultItem->setText(0,"结果");
  151. QTreeWidgetItem* IrItem = new QTreeWidgetItem(mTree);
  152. IrItem->setText(0,"IR计算");
  153. mTree->addTopLevelItem(IrItem);
  154. QTreeWidgetItem* IrSetItem = new QTreeWidgetItem(IrItem);
  155. IrSetItem->setText(0,"设置");
  156. QTreeWidgetItem* IrCalcItem = new QTreeWidgetItem(IrItem);
  157. IrCalcItem->setText(0,"计算");
  158. QTreeWidgetItem* IrResultItem = new QTreeWidgetItem(IrItem);
  159. IrResultItem->setText(0,"结果");
  160. QTreeWidgetItem* ResultItem = new QTreeWidgetItem(mTree);
  161. ResultItem->setText(0,"结果展示");
  162. mTree->addTopLevelItem(ResultItem);
  163. mTree->expandAll();
  164. connect(mTree,&QTreeWidget::itemClicked,this,&MainWindow::pageSwitch);
  165. }
  166. void MainWindow::initStack()
  167. {
  168. mStack = new QStackedWidget;
  169. QLabel* page0 = new QLabel(" ");
  170. mStack->addWidget(page0);
  171. // QLabel* page1 = new QLabel("model");
  172. mStack->addWidget(mModelPage);
  173. QLabel* page2 = new QLabel("grid");
  174. mStack->addWidget(page2);
  175. QLabel* page3 = new QLabel("CFD");
  176. mStack->addWidget(page3);
  177. QLabel* page4 = new QLabel("IR");
  178. mStack->addWidget(page4);
  179. QLabel* page5 = new QLabel("Result");
  180. mStack->addWidget(page5);
  181. mStack->setCurrentIndex(0);
  182. }
  183. void MainWindow::pageSwitch(QTreeWidgetItem* item,int column)
  184. {
  185. if(item->text(column) == "模型")
  186. {
  187. if(mStack->currentIndex() != 1)
  188. {
  189. m_edit->append("模型");
  190. }
  191. mStack->setCurrentIndex(1);
  192. }
  193. if(item->text(column) == "网格")
  194. {
  195. if(mStack->currentIndex() != 2)
  196. {
  197. m_edit->append("网格");
  198. }
  199. mStack->setCurrentIndex(2);
  200. }
  201. if(item->text(column) == "CFD计算"|| (item->parent() != NULL && item->parent()->text(column) == "CFD计算"))
  202. {
  203. m_edit->append("CFD计算");
  204. mStack->setCurrentIndex(3);
  205. }
  206. if(item->text(column) == "IR计算"||(item->parent() != NULL && item->parent()->text(column) == "IR计算"))
  207. {
  208. m_edit->append("IR计算");
  209. mStack->setCurrentIndex(4);
  210. }
  211. if(item->text(column) == "结果展示")
  212. {
  213. m_edit->append("结果展示");
  214. mStack->setCurrentIndex(5);
  215. }
  216. }
  217. void MainWindow::createCategoryFile(SARibbonCategory* page)
  218. {
  219. SARibbonPannel* pannelModel = page->addPannel(("Model Operator"));
  220. QAction *actInput = createAction(tr("导入模型"),":/icon/doc/modelinput.svg");
  221. pannelModel->addLargeAction(actInput);
  222. QAction *actOutput = createAction(tr("导出模型"),":/icon/doc/outputmodel.svg");
  223. pannelModel->addLargeAction(actOutput);
  224. connect(actOutput,&QAction::triggered,this,[this](bool){
  225. QFileDialog* inputDig = new QFileDialog(this);
  226. inputDig->getExistingDirectory(this,"导出模型","./");
  227. });
  228. connect(actInput,&QAction::triggered,this,[this](){
  229. mModelAdd = new ModelAdd();
  230. connect(mModelAdd,&ModelAdd::addModel,this,&MainWindow::addModelComplete);
  231. connect(mModelAdd,&ModelAdd::sendModel,mModelPage,&ModelPage::onShowNews);
  232. mModelAdd->setAttribute(Qt::WA_DeleteOnClose);
  233. mModelAdd->exec();
  234. });
  235. SARibbonPannel* pannelFile = page->addPannel(("File Operator"));
  236. QAction *createNew = createAction(tr("新建"),":/icon/doc/icons/pqNewFolder.svg");
  237. pannelFile->addLargeAction(createNew);
  238. QAction *openFile = createAction(tr("读取"),":/icon/doc/icons/pqOpen.svg");
  239. pannelFile->addLargeAction(openFile);
  240. QAction *saveFile = createAction(tr("保存"),":/icon/doc/icons/pqSave.svg");
  241. pannelFile->addLargeAction(saveFile);
  242. QAction *closeFile = createAction(tr("关闭"),":/icon/doc/icons/pqExitApp.svg");
  243. pannelFile->addLargeAction(closeFile);
  244. }
  245. void MainWindow::createCategoryDisplay(SARibbonCategory* page)
  246. {
  247. SARibbonPannel* choseDisplayPannel = page->addPannel(("chose window display"));
  248. QAction *displayAll = createAction(tr("显示所有"),":/icon/doc/icons/pqEyeball.svg","displayAll");
  249. displayAll->setCheckable(true);
  250. choseDisplayPannel->addLargeAction(displayAll);
  251. QAction *displayMainWindow = createAction(tr("显示图形窗口"),":/icon/doc/icons/pqWindow16@2x.png","displayMainWindow");
  252. displayMainWindow->setCheckable(true);
  253. choseDisplayPannel->addLargeAction(displayMainWindow);
  254. QAction *displayMenu = createAction(tr("显示对象树"),":/icon/doc/icons/pqSplitHorizontal.svg","displayMenu");
  255. displayMenu->setCheckable(true);
  256. choseDisplayPannel->addLargeAction(displayMenu);
  257. QAction *displayControlDesk = createAction(tr("显示控制台"),":/icon/doc/icons/pqSplitVertical.svg","displayControlDesk");
  258. displayControlDesk->setCheckable(true);
  259. choseDisplayPannel->addLargeAction(displayControlDesk);
  260. SARibbonPannel* optionSettingPannel = page->addPannel(("change options"));
  261. QAction *optionAct = createAction(tr("选项(O)"),":/icon/doc/icons/pqAdvanced.svg");
  262. optionSettingPannel->addLargeAction(optionAct);
  263. }
  264. void MainWindow::createCategoryData(SARibbonCategory* page)
  265. {
  266. SARibbonPannel* dataPannel = page->addPannel(("dataBase"));
  267. QAction *materialDataAct = createAction(tr("材料数据库"),":/icon/doc/database.svg");
  268. dataPannel->addLargeAction(materialDataAct);
  269. QAction *gasDataAct = createAction(tr("气体数据库"),":/icon/doc/database.svg");
  270. dataPannel->addLargeAction(gasDataAct);
  271. QAction *probesDataAct = createAction(tr("探测器数据库"),":/icon/doc/database.svg");
  272. dataPannel->addLargeAction(probesDataAct);
  273. QAction *envirDataAct = createAction(tr("环境数据库"),":/icon/doc/database.svg");
  274. dataPannel->addLargeAction(envirDataAct);
  275. }
  276. void MainWindow::createCategoryGrid(SARibbonCategory* page)
  277. {
  278. SARibbonPannel* gridPannel = page->addPannel(("grid"));
  279. QAction *createFaceAct = createAction(tr("生成面网格"),":/icon/doc/icons/pqFaceMapData.svg");
  280. gridPannel->addLargeAction(createFaceAct);
  281. QAction *createCubicAct = createAction(tr("生成体网格"),":/icon/doc/icons/pqGhostCellsGenerator.svg");
  282. gridPannel->addLargeAction(createCubicAct);
  283. QAction *delGridAct = createAction(tr("删除网格"),":/icon/doc/icons/pqResetActorsPosition.svg");
  284. gridPannel->addLargeAction(delGridAct);
  285. QAction *gridInfoAct = createAction(tr("网格信息"),":/icon/doc/icons/pqEdgeCenterData.svg");
  286. gridPannel->addLargeAction(gridInfoAct);
  287. QAction *gridSegmentAct = createAction(tr("网格细分"),":/icon/doc/icons/pqClip.svg");
  288. gridPannel->addLargeAction(gridSegmentAct);
  289. SARibbonPannel* gridCheckPannel = page->addPannel(("grid Check"));
  290. QAction *gridCheckAct = createAction(tr("网格质量检查"),":/icon/doc/icons/pqFullscreen.svg");
  291. gridCheckPannel->addLargeAction(gridCheckAct);
  292. QAction *gridOptimisticAct = createAction(tr("网格质量优化"),":/icon/doc/icons/pqGlyph.svg");
  293. gridCheckPannel->addLargeAction(gridOptimisticAct);
  294. }
  295. void MainWindow::createCategoryHelp(SARibbonCategory* page)
  296. {
  297. SARibbonPannel* helpPannel = page->addPannel(("help Pannel"));
  298. QAction *operatManuals = createAction(tr("操作手册"),":/icon/doc/icons/pqMultiBlockData16.png");
  299. helpPannel->addLargeAction(operatManuals);
  300. QAction *licenseAct = createAction(tr("License"),":/icon/doc/cc-license.svg");
  301. helpPannel->addLargeAction(licenseAct);
  302. QAction *aboutAct = createAction(tr("关于软件"),":/icon/doc/icons/pqLightOn.svg");
  303. connect(aboutAct,&QAction::triggered,this,&MainWindow::onActionAboutTriggered);
  304. helpPannel->addLargeAction(aboutAct);
  305. }
  306. void MainWindow::onActionAboutTriggered()
  307. {
  308. QMessageBox::information(this,
  309. tr("about us:"),
  310. tr("\n ======================="
  311. "\n SARibbonBar version:0.9"
  312. "\n Author:南京航天航空大学"
  313. "\n Email:nuaa@163.com"
  314. "\n =======================")
  315. );
  316. }
  317. void MainWindow::createQuickAccessBar(SARibbonQuickAccessBar* quickAccessBar)
  318. {
  319. }
  320. void MainWindow::createRightButtonGroup(SARibbonButtonGroupWidget* rightBar)
  321. {
  322. }
  323. QAction* MainWindow::createAction(const QString& text, const QString& iconurl, const QString& objName)
  324. {
  325. QAction* act = new QAction(this);
  326. act->setText(text);
  327. act->setIcon(QIcon(iconurl));
  328. act->setObjectName(objName);
  329. return act;
  330. }
  331. QAction* MainWindow::createAction(const QString& text, const QString& iconurl)
  332. {
  333. QAction* act = new QAction(this);
  334. act->setText(text);
  335. act->setIcon(QIcon(iconurl));
  336. act->setObjectName(text);
  337. return act;
  338. }
  339. void MainWindow::addModelComplete()
  340. {
  341. mModelAdd->close();
  342. mStack->setCurrentIndex(1);
  343. }