mainwindow.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. addTreeList(mTreeList);
  62. mConsole = new QDockWidget("控制台",this);
  63. addDockWidget(Qt::BottomDockWidgetArea,mConsole);
  64. mConsole->setAllowedAreas(Qt::BottomDockWidgetArea);
  65. mCent = new QDockWidget("主界面",this);
  66. addDockWidget(Qt::RightDockWidgetArea,mCent);
  67. mCent->setFeatures(QDockWidget::NoDockWidgetFeatures);
  68. setCorner(Qt::BottomLeftCorner,Qt::LeftDockWidgetArea);
  69. setCentralWidget(mCent);
  70. SAFramelessHelper* helper = framelessHelper();
  71. helper->setRubberBandOnResize(false);
  72. //setWindowTitle(("ribbon mainwindow test"));
  73. m_edit = new QTextEdit(this);
  74. mConsole->setWidget(m_edit);
  75. setStatusBar(new QStatusBar());
  76. SARibbonBar* ribbon = ribbonBar();
  77. //通过setContentsMargins设置ribbon四周的间距
  78. ribbon->setContentsMargins(5, 0, 5, 0);
  79. //设置applicationButton
  80. PRINT_COST("setCentralWidget & setWindowTitle");
  81. ribbon->applicationButton()->setText(("File"));
  82. ribbon->applicationButton()->hide();
  83. //添加主标签页 - 通过addCategoryPage工厂函数添加
  84. SARibbonCategory* categoryFile = ribbon->addCategoryPage(tr("文件(F)"));
  85. categoryFile->setObjectName(("categoryFile"));
  86. createCategoryFile(categoryFile);
  87. PRINT_COST("new main page");
  88. //添加显示标签页 - 直接new SARibbonCategory添加
  89. SARibbonCategory* categoryDisplay = new SARibbonCategory();
  90. categoryDisplay->setCategoryName(tr("显示(S)"));
  91. categoryDisplay->setObjectName(("categoryDisplay"));
  92. createCategoryDisplay(categoryDisplay);
  93. ribbon->addCategoryPage(categoryDisplay);
  94. PRINT_COST("add categoryDisplay page");
  95. //添加数据标签页
  96. SARibbonCategory* categoryData = new SARibbonCategory();
  97. categoryData->setCategoryName(("数据(D)"));
  98. categoryData->setObjectName(("categoryDelete"));
  99. ribbon->addCategoryPage(categoryData);
  100. createCategoryData(categoryData);
  101. PRINT_COST("add category categoryData page");
  102. //添加导入标签页
  103. SARibbonCategory* categoryGrid = new SARibbonCategory();
  104. categoryGrid->setCategoryName(("网格(G)"));
  105. categoryGrid->setObjectName(("categoryGrid"));
  106. ribbon->addCategoryPage(categoryGrid);
  107. createCategoryGrid(categoryGrid);
  108. PRINT_COST("add category categoryGrid page");
  109. //添加帮助标签页
  110. SARibbonCategory* categoryHelp = new SARibbonCategory();
  111. categoryHelp->setCategoryName(("帮助(H)"));
  112. categoryHelp->setObjectName(("categoryHelp"));
  113. ribbon->addCategoryPage(categoryHelp);
  114. createCategoryHelp(categoryHelp);
  115. PRINT_COST("add category help page");
  116. SARibbonQuickAccessBar* quickAccessBar = ribbon->quickAccessBar();
  117. createQuickAccessBar(quickAccessBar);
  118. PRINT_COST("add quick access bar");
  119. SARibbonButtonGroupWidget* rightBar = ribbon->rightButtonGroup();
  120. createRightButtonGroup(rightBar);
  121. PRINT_COST("add right bar");
  122. setMinimumWidth(1000);
  123. showMaximized();
  124. ribbonBar()->setRibbonStyle(SARibbonBar::WpsLiteStyleTwoRow);
  125. }
  126. void MainWindow::addTreeList(QDockWidget* widget)
  127. {
  128. QTreeWidget *tree = new QTreeWidget();
  129. tree->setHeaderHidden(true);
  130. QTreeWidgetItem* modelItem = new QTreeWidgetItem(tree);
  131. modelItem->setText(0,"模型");
  132. tree->addTopLevelItem(modelItem);
  133. QTreeWidgetItem* gridItem = new QTreeWidgetItem(tree);
  134. gridItem->setText(0,"网格");
  135. tree->addTopLevelItem(gridItem);
  136. QTreeWidgetItem* CfdItem = new QTreeWidgetItem(tree);
  137. CfdItem->setText(0,"CFD计算");
  138. tree->addTopLevelItem(CfdItem);
  139. QTreeWidgetItem* CfdSetItem = new QTreeWidgetItem(CfdItem);
  140. CfdSetItem->setText(0,"设置");
  141. QTreeWidgetItem* CfdCalcItem = new QTreeWidgetItem(CfdItem);
  142. CfdCalcItem->setText(0,"计算");
  143. QTreeWidgetItem* CfdResultItem = new QTreeWidgetItem(CfdItem);
  144. CfdResultItem->setText(0,"结果");
  145. QTreeWidgetItem* IrItem = new QTreeWidgetItem(tree);
  146. IrItem->setText(0,"IR计算");
  147. tree->addTopLevelItem(IrItem);
  148. QTreeWidgetItem* IrSetItem = new QTreeWidgetItem(IrItem);
  149. IrSetItem->setText(0,"设置");
  150. QTreeWidgetItem* IrCalcItem = new QTreeWidgetItem(IrItem);
  151. IrCalcItem->setText(0,"计算");
  152. QTreeWidgetItem* IrResultItem = new QTreeWidgetItem(IrItem);
  153. IrResultItem->setText(0,"结果");
  154. QTreeWidgetItem* ResultItem = new QTreeWidgetItem(tree);
  155. ResultItem->setText(0,"结果展示");
  156. tree->addTopLevelItem(ResultItem);
  157. widget->setWidget(tree);
  158. }
  159. void MainWindow::createCategoryFile(SARibbonCategory* page)
  160. {
  161. }
  162. void MainWindow::createCategoryDisplay(SARibbonCategory* page)
  163. {
  164. }
  165. void MainWindow::createCategoryData(SARibbonCategory* page)
  166. {
  167. }
  168. void MainWindow::createCategoryGrid(SARibbonCategory* page)
  169. {
  170. }
  171. void MainWindow::createCategoryHelp(SARibbonCategory* page)
  172. {
  173. }
  174. void MainWindow::createQuickAccessBar(SARibbonQuickAccessBar* quickAccessBar)
  175. {
  176. }
  177. void MainWindow::createRightButtonGroup(SARibbonButtonGroupWidget* rightBar)
  178. {
  179. }