mainwindow.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. //菜单栏
  59. mTreeList = new QDockWidget("菜单",this);
  60. mTreeList->setFeatures(QDockWidget::NoDockWidgetFeatures);
  61. addDockWidget(Qt::LeftDockWidgetArea,mTreeList);
  62. initTree();
  63. mTreeList->setWidget(mTree);
  64. //主界面
  65. mCent = new QDockWidget("主界面",this);
  66. addDockWidget(Qt::RightDockWidgetArea,mCent);
  67. mCent->setFeatures(QDockWidget::NoDockWidgetFeatures);
  68. setCorner(Qt::BottomLeftCorner,Qt::LeftDockWidgetArea);
  69. initStack();
  70. mCent->setWidget(mStack);
  71. setCentralWidget(mCent);
  72. //控制台
  73. mConsole = new QDockWidget("控制台",this);
  74. addDockWidget(Qt::BottomDockWidgetArea,mConsole);
  75. mConsole->setAllowedAreas(Qt::BottomDockWidgetArea);
  76. SAFramelessHelper* helper = framelessHelper();
  77. helper->setRubberBandOnResize(false);
  78. m_edit = new QTextEdit(this);
  79. mConsole->setWidget(m_edit);
  80. setStatusBar(new QStatusBar());
  81. SARibbonBar* ribbon = ribbonBar();
  82. //通过setContentsMargins设置ribbon四周的间距
  83. ribbon->setContentsMargins(5, 0, 5, 0);
  84. //设置applicationButton
  85. PRINT_COST("setCentralWidget & setWindowTitle");
  86. ribbon->applicationButton()->setText(("File"));
  87. ribbon->applicationButton()->hide();
  88. //添加主标签页 - 通过addCategoryPage工厂函数添加
  89. SARibbonCategory* categoryFile = ribbon->addCategoryPage(tr("文件(F)"));
  90. categoryFile->setObjectName(("categoryFile"));
  91. createCategoryFile(categoryFile);
  92. PRINT_COST("new main page");
  93. //添加显示标签页 - 直接new SARibbonCategory添加
  94. SARibbonCategory* categoryDisplay = new SARibbonCategory();
  95. categoryDisplay->setCategoryName(tr("显示(S)"));
  96. categoryDisplay->setObjectName(("categoryDisplay"));
  97. createCategoryDisplay(categoryDisplay);
  98. ribbon->addCategoryPage(categoryDisplay);
  99. PRINT_COST("add categoryDisplay page");
  100. //添加数据标签页
  101. SARibbonCategory* categoryData = new SARibbonCategory();
  102. categoryData->setCategoryName(("数据(D)"));
  103. categoryData->setObjectName(("categoryDelete"));
  104. ribbon->addCategoryPage(categoryData);
  105. createCategoryData(categoryData);
  106. PRINT_COST("add category categoryData page");
  107. //添加导入标签页
  108. SARibbonCategory* categoryGrid = new SARibbonCategory();
  109. categoryGrid->setCategoryName(("网格(G)"));
  110. categoryGrid->setObjectName(("categoryGrid"));
  111. ribbon->addCategoryPage(categoryGrid);
  112. createCategoryGrid(categoryGrid);
  113. PRINT_COST("add category categoryGrid page");
  114. //添加帮助标签页
  115. SARibbonCategory* categoryHelp = new SARibbonCategory();
  116. categoryHelp->setCategoryName(("帮助(H)"));
  117. categoryHelp->setObjectName(("categoryHelp"));
  118. ribbon->addCategoryPage(categoryHelp);
  119. createCategoryHelp(categoryHelp);
  120. PRINT_COST("add category help page");
  121. SARibbonQuickAccessBar* quickAccessBar = ribbon->quickAccessBar();
  122. createQuickAccessBar(quickAccessBar);
  123. PRINT_COST("add quick access bar");
  124. SARibbonButtonGroupWidget* rightBar = ribbon->rightButtonGroup();
  125. createRightButtonGroup(rightBar);
  126. PRINT_COST("add right bar");
  127. setMinimumWidth(800);
  128. showMaximized();
  129. ribbonBar()->setRibbonStyle(SARibbonBar::WpsLiteStyleTwoRow);
  130. }
  131. void MainWindow::initTree()
  132. {
  133. mTree = new QTreeWidget();
  134. mTree->setHeaderHidden(true);
  135. QTreeWidgetItem* modelItem = new QTreeWidgetItem(mTree);
  136. modelItem->setText(0,"模型");
  137. mTree->addTopLevelItem(modelItem);
  138. QTreeWidgetItem* gridItem = new QTreeWidgetItem(mTree);
  139. gridItem->setText(0,"网格");
  140. mTree->addTopLevelItem(gridItem);
  141. QTreeWidgetItem* CfdItem = new QTreeWidgetItem(mTree);
  142. CfdItem->setText(0,"CFD计算");
  143. mTree->addTopLevelItem(CfdItem);
  144. QTreeWidgetItem* CfdSetItem = new QTreeWidgetItem(CfdItem);
  145. CfdSetItem->setText(0,"设置");
  146. QTreeWidgetItem* CfdCalcItem = new QTreeWidgetItem(CfdItem);
  147. CfdCalcItem->setText(0,"计算");
  148. QTreeWidgetItem* CfdResultItem = new QTreeWidgetItem(CfdItem);
  149. CfdResultItem->setText(0,"结果");
  150. QTreeWidgetItem* IrItem = new QTreeWidgetItem(mTree);
  151. IrItem->setText(0,"IR计算");
  152. mTree->addTopLevelItem(IrItem);
  153. QTreeWidgetItem* IrSetItem = new QTreeWidgetItem(IrItem);
  154. IrSetItem->setText(0,"设置");
  155. QTreeWidgetItem* IrCalcItem = new QTreeWidgetItem(IrItem);
  156. IrCalcItem->setText(0,"计算");
  157. QTreeWidgetItem* IrResultItem = new QTreeWidgetItem(IrItem);
  158. IrResultItem->setText(0,"结果");
  159. QTreeWidgetItem* ResultItem = new QTreeWidgetItem(mTree);
  160. ResultItem->setText(0,"结果展示");
  161. mTree->addTopLevelItem(ResultItem);
  162. mTree->expandAll();
  163. connect(mTree,&QTreeWidget::itemClicked,this,&MainWindow::pageSwitch);
  164. }
  165. void MainWindow::initStack()
  166. {
  167. mStack = new QStackedWidget;
  168. QLabel* page0 = new QLabel("background");
  169. mStack->addWidget(page0);
  170. QLabel* page1 = new QLabel("model");
  171. mStack->addWidget(page1);
  172. QLabel* page2 = new QLabel("grid");
  173. mStack->addWidget(page2);
  174. QLabel* page3 = new QLabel("CFD");
  175. mStack->addWidget(page3);
  176. QLabel* page4 = new QLabel("IR");
  177. mStack->addWidget(page4);
  178. QLabel* page5 = new QLabel("Result");
  179. mStack->addWidget(page5);
  180. mStack->setCurrentIndex(0);
  181. }
  182. void MainWindow::pageSwitch(QTreeWidgetItem* item,int column)
  183. {
  184. if(item->text(column) == "模型")
  185. {
  186. if(mStack->currentIndex() != 1)
  187. {
  188. m_edit->append("模型");
  189. }
  190. mStack->setCurrentIndex(1);
  191. }
  192. if(item->text(column) == "网格")
  193. {
  194. if(mStack->currentIndex() != 2)
  195. {
  196. m_edit->append("网格");
  197. }
  198. mStack->setCurrentIndex(2);
  199. }
  200. if(item->text(column) == "CFD计算"|| (item->parent() != NULL && item->parent()->text(column) == "CFD计算"))
  201. {
  202. m_edit->append("CFD计算");
  203. mStack->setCurrentIndex(3);
  204. }
  205. if(item->text(column) == "IR计算"||(item->parent() != NULL && item->parent()->text(column) == "IR计算"))
  206. {
  207. m_edit->append("IR计算");
  208. mStack->setCurrentIndex(4);
  209. }
  210. if(item->text(column) == "结果展示")
  211. {
  212. m_edit->append("结果展示");
  213. mStack->setCurrentIndex(5);
  214. }
  215. }
  216. void MainWindow::createCategoryFile(SARibbonCategory* page)
  217. {
  218. SARibbonPannel* pannelFile = page->addPannel(("File Operator"));
  219. QAction *actOutput = createAction(tr("导入"),":/icon/doc/icons/min.png");
  220. pannelFile->addLargeAction(actOutput);
  221. QAction *actInput = createAction(tr("导出"),":/icon/doc/icons/add.png");
  222. pannelFile->addLargeAction(actInput);
  223. }
  224. void MainWindow::createCategoryDisplay(SARibbonCategory* page)
  225. {
  226. }
  227. void MainWindow::createCategoryData(SARibbonCategory* page)
  228. {
  229. }
  230. void MainWindow::createCategoryGrid(SARibbonCategory* page)
  231. {
  232. }
  233. void MainWindow::createCategoryHelp(SARibbonCategory* page)
  234. {
  235. }
  236. void MainWindow::createQuickAccessBar(SARibbonQuickAccessBar* quickAccessBar)
  237. {
  238. }
  239. void MainWindow::createRightButtonGroup(SARibbonButtonGroupWidget* rightBar)
  240. {
  241. }
  242. QAction* MainWindow::createAction(const QString& text, const QString& iconurl, const QString& objName)
  243. {
  244. QAction* act = new QAction(this);
  245. act->setText(text);
  246. act->setIcon(QIcon(iconurl));
  247. act->setObjectName(objName);
  248. return act;
  249. }
  250. QAction* MainWindow::createAction(const QString& text, const QString& iconurl)
  251. {
  252. QAction* act = new QAction(this);
  253. act->setText(text);
  254. act->setIcon(QIcon(iconurl));
  255. act->setObjectName(text);
  256. return act;
  257. }