mainwindow.cpp 9.4 KB

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