123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- #include "mainwindow.h"
- #include <QApplication>
- #include <QFile>
- #include <QTextEdit>
- #include <QAbstractButton>
- #include <QFileDialog>
- #include "SARibbonBar.h"
- #include "SARibbonCategory.h"
- #include <QPushButton>
- #include <QMessageBox>
- #include "SARibbonPannel.h"
- #include "SARibbonToolButton.h"
- #include <QAction>
- #include <QMenu>
- #include <QStatusBar>
- #include <QDebug>
- #include <QElapsedTimer>
- #include <QRadioButton>
- #include <QButtonGroup>
- #include <QSpinBox>
- #include <QSplitter>
- #include <QLineEdit>
- #include <QCalendarWidget>
- #include <QXmlStreamWriter>
- #include <QTextStream>
- #include <QFontComboBox>
- #include <QLabel>
- #include "SARibbonMenu.h"
- #include "SARibbonComboBox.h"
- #include "SARibbonLineEdit.h"
- #include "SARibbonGallery.h"
- #include "SARibbonCheckBox.h"
- #include "SARibbonQuickAccessBar.h"
- #include "SARibbonButtonGroupWidget.h"
- #include "SARibbonApplicationButton.h"
- #include "SARibbonCustomizeWidget.h"
- #include "SARibbonElementManager.h"
- #include "SARibbonCustomizeDialog.h"
- #include "SARibbonColorToolButton.h"
- #include "SAFramelessHelper.h"
- #include "colorWidgets/SAColorPaletteGridWidget.h"
- #include "colorWidgets/SAColorGridWidget.h"
- #include <QDockWidget>
- #define PRINT_COST_START() \
- QElapsedTimer __TMP_COST; \
- __TMP_COST.start(); \
- int __TMP_LASTTIMES = 0
- #define PRINT_COST(STR) \
- do { \
- int ___TMP_INT = __TMP_COST.elapsed(); \
- qDebug() << STR << " cost " << ___TMP_INT - __TMP_LASTTIMES << " ms (" << ___TMP_INT << ")"; \
- m_edit->append(QString("%1 cost %2 ms(%3)").arg(STR).arg(___TMP_INT - __TMP_LASTTIMES).arg(___TMP_INT)); \
- __TMP_LASTTIMES = ___TMP_INT; \
- } while (0)
- MainWindow::MainWindow(QWidget* par) : SARibbonMainWindow(par), m_customizeWidget(nullptr)
- {
- PRINT_COST_START();
- mModelPage = new ModelPage();
- //菜单栏
- mTreeList = new QDockWidget("菜单",this);
- mTreeList->setFeatures(QDockWidget::NoDockWidgetFeatures);
- addDockWidget(Qt::LeftDockWidgetArea,mTreeList);
- initTree();
- mTreeList->setWidget(mTree);
- //主界面
- mCent = new QDockWidget("主界面",this);
- addDockWidget(Qt::RightDockWidgetArea,mCent);
- mCent->setFeatures(QDockWidget::NoDockWidgetFeatures);
- setCorner(Qt::BottomLeftCorner,Qt::LeftDockWidgetArea);
- initStack();
- mCent->setWidget(mStack);
- setCentralWidget(mCent);
- //控制台
- mConsole = new QDockWidget("控制台",this);
- addDockWidget(Qt::BottomDockWidgetArea,mConsole);
- mConsole->setAllowedAreas(Qt::BottomDockWidgetArea);
- SAFramelessHelper* helper = framelessHelper();
- helper->setRubberBandOnResize(false);
- m_edit = new QTextEdit(this);
- mConsole->setWidget(m_edit);
- setStatusBar(new QStatusBar());
- SARibbonBar* ribbon = ribbonBar();
- //通过setContentsMargins设置ribbon四周的间距
- ribbon->setContentsMargins(5, 0, 5,0);
- //设置applicationButton
- PRINT_COST("setCentralWidget & setWindowTitle");
- ribbon->applicationButton()->setText(("File"));
- ribbon->applicationButton()->hide();
- //添加主标签页 - 通过addCategoryPage工厂函数添加
- SARibbonCategory* categoryFile = ribbon->addCategoryPage(tr("文件(F)"));
- categoryFile->setObjectName(("categoryFile"));
- createCategoryFile(categoryFile);
- PRINT_COST("new main page");
- //添加显示标签页 - 直接new SARibbonCategory添加
- SARibbonCategory* categoryDisplay = new SARibbonCategory();
- categoryDisplay->setCategoryName(tr("显示(S)"));
- categoryDisplay->setObjectName(("categoryDisplay"));
- createCategoryDisplay(categoryDisplay);
- ribbon->addCategoryPage(categoryDisplay);
- PRINT_COST("add categoryDisplay page");
- //添加数据标签页
- SARibbonCategory* categoryData = new SARibbonCategory();
- categoryData->setCategoryName(("数据(D)"));
- categoryData->setObjectName(("categoryDelete"));
- ribbon->addCategoryPage(categoryData);
- createCategoryData(categoryData);
- PRINT_COST("add category categoryData page");
- //添加导入标签页
- SARibbonCategory* categoryGrid = new SARibbonCategory();
- categoryGrid->setCategoryName(("网格(G)"));
- categoryGrid->setObjectName(("categoryGrid"));
- ribbon->addCategoryPage(categoryGrid);
- createCategoryGrid(categoryGrid);
- PRINT_COST("add category categoryGrid page");
- //添加帮助标签页
- SARibbonCategory* categoryHelp = new SARibbonCategory();
- categoryHelp->setCategoryName(("帮助(H)"));
- categoryHelp->setObjectName(("categoryHelp"));
- ribbon->addCategoryPage(categoryHelp);
- createCategoryHelp(categoryHelp);
- PRINT_COST("add category help page");
- SARibbonQuickAccessBar* quickAccessBar = ribbon->quickAccessBar();
- createQuickAccessBar(quickAccessBar);
- PRINT_COST("add quick access bar");
- SARibbonButtonGroupWidget* rightBar = ribbon->rightButtonGroup();
- createRightButtonGroup(rightBar);
- PRINT_COST("add right bar");
- setMinimumWidth(800);
- showMaximized();
- ribbonBar()->setRibbonStyle(SARibbonBar::WpsLiteStyleTwoRow);
- }
- void MainWindow::initTree()
- {
- mTree = new QTreeWidget();
- mTree->setHeaderHidden(true);
- QTreeWidgetItem* modelItem = new QTreeWidgetItem(mTree);
- modelItem->setText(0,"模型");
- mTree->addTopLevelItem(modelItem);
- QTreeWidgetItem* gridItem = new QTreeWidgetItem(mTree);
- gridItem->setText(0,"网格");
- mTree->addTopLevelItem(gridItem);
- QTreeWidgetItem* CfdItem = new QTreeWidgetItem(mTree);
- CfdItem->setText(0,"CFD计算");
- mTree->addTopLevelItem(CfdItem);
- QTreeWidgetItem* CfdSetItem = new QTreeWidgetItem(CfdItem);
- CfdSetItem->setText(0,"设置");
- QTreeWidgetItem* CfdCalcItem = new QTreeWidgetItem(CfdItem);
- CfdCalcItem->setText(0,"计算");
- QTreeWidgetItem* CfdResultItem = new QTreeWidgetItem(CfdItem);
- CfdResultItem->setText(0,"结果");
- QTreeWidgetItem* IrItem = new QTreeWidgetItem(mTree);
- IrItem->setText(0,"IR计算");
- mTree->addTopLevelItem(IrItem);
- QTreeWidgetItem* IrSetItem = new QTreeWidgetItem(IrItem);
- IrSetItem->setText(0,"设置");
- QTreeWidgetItem* IrCalcItem = new QTreeWidgetItem(IrItem);
- IrCalcItem->setText(0,"计算");
- QTreeWidgetItem* IrResultItem = new QTreeWidgetItem(IrItem);
- IrResultItem->setText(0,"结果");
- QTreeWidgetItem* ResultItem = new QTreeWidgetItem(mTree);
- ResultItem->setText(0,"结果展示");
- mTree->addTopLevelItem(ResultItem);
- mTree->expandAll();
- connect(mTree,&QTreeWidget::itemClicked,this,&MainWindow::pageSwitch);
- }
- void MainWindow::initStack()
- {
- mStack = new QStackedWidget;
- QLabel* page0 = new QLabel(" ");
- mStack->addWidget(page0);
- // QLabel* page1 = new QLabel("model");
- mStack->addWidget(mModelPage);
- QLabel* page2 = new QLabel("grid");
- mStack->addWidget(page2);
- QLabel* page3 = new QLabel("CFD");
- mStack->addWidget(page3);
- QLabel* page4 = new QLabel("IR");
- mStack->addWidget(page4);
- QLabel* page5 = new QLabel("Result");
- mStack->addWidget(page5);
- mStack->setCurrentIndex(0);
- }
- void MainWindow::pageSwitch(QTreeWidgetItem* item,int column)
- {
- if(item->text(column) == "模型")
- {
- if(mStack->currentIndex() != 1)
- {
- m_edit->append("模型");
- }
- mStack->setCurrentIndex(1);
- }
- if(item->text(column) == "网格")
- {
- if(mStack->currentIndex() != 2)
- {
- m_edit->append("网格");
- }
- mStack->setCurrentIndex(2);
- }
- if(item->text(column) == "CFD计算"|| (item->parent() != NULL && item->parent()->text(column) == "CFD计算"))
- {
- m_edit->append("CFD计算");
- mStack->setCurrentIndex(3);
- }
- if(item->text(column) == "IR计算"||(item->parent() != NULL && item->parent()->text(column) == "IR计算"))
- {
- m_edit->append("IR计算");
- mStack->setCurrentIndex(4);
- }
- if(item->text(column) == "结果展示")
- {
- m_edit->append("结果展示");
- mStack->setCurrentIndex(5);
- }
- }
- void MainWindow::createCategoryFile(SARibbonCategory* page)
- {
- SARibbonPannel* pannelModel = page->addPannel(("Model Operator"));
- QAction *actInput = createAction(tr("导入模型"),":/icon/doc/modelinput.svg");
- pannelModel->addLargeAction(actInput);
- QAction *actOutput = createAction(tr("导出模型"),":/icon/doc/outputmodel.svg");
- pannelModel->addLargeAction(actOutput);
- connect(actOutput,&QAction::triggered,this,[this](bool){
- QFileDialog* inputDig = new QFileDialog(this);
- inputDig->getExistingDirectory(this,"导出模型","./");
- });
- connect(actInput,&QAction::triggered,this,[this](){
- mModelAdd = new ModelAdd();
- connect(mModelAdd,&ModelAdd::addModel,this,&MainWindow::addModelComplete);
- connect(mModelAdd,&ModelAdd::sendModel,mModelPage,&ModelPage::onShowNews);
- mModelAdd->setAttribute(Qt::WA_DeleteOnClose);
- mModelAdd->exec();
- });
- SARibbonPannel* pannelFile = page->addPannel(("File Operator"));
- QAction *createNew = createAction(tr("新建"),":/icon/doc/icons/pqNewFolder.svg");
- pannelFile->addLargeAction(createNew);
- QAction *openFile = createAction(tr("读取"),":/icon/doc/icons/pqOpen.svg");
- pannelFile->addLargeAction(openFile);
- QAction *saveFile = createAction(tr("保存"),":/icon/doc/icons/pqSave.svg");
- pannelFile->addLargeAction(saveFile);
- QAction *closeFile = createAction(tr("关闭"),":/icon/doc/icons/pqExitApp.svg");
- pannelFile->addLargeAction(closeFile);
- }
- void MainWindow::createCategoryDisplay(SARibbonCategory* page)
- {
- SARibbonPannel* choseDisplayPannel = page->addPannel(("chose window display"));
- QAction *displayAll = createAction(tr("显示所有"),":/icon/doc/icons/pqEyeball.svg","displayAll");
- displayAll->setCheckable(true);
- choseDisplayPannel->addLargeAction(displayAll);
- QAction *displayMainWindow = createAction(tr("显示图形窗口"),":/icon/doc/icons/pqWindow16@2x.png","displayMainWindow");
- displayMainWindow->setCheckable(true);
- choseDisplayPannel->addLargeAction(displayMainWindow);
- QAction *displayMenu = createAction(tr("显示对象树"),":/icon/doc/icons/pqSplitHorizontal.svg","displayMenu");
- displayMenu->setCheckable(true);
- choseDisplayPannel->addLargeAction(displayMenu);
- QAction *displayControlDesk = createAction(tr("显示控制台"),":/icon/doc/icons/pqSplitVertical.svg","displayControlDesk");
- displayControlDesk->setCheckable(true);
- choseDisplayPannel->addLargeAction(displayControlDesk);
- SARibbonPannel* optionSettingPannel = page->addPannel(("change options"));
- QAction *optionAct = createAction(tr("选项(O)"),":/icon/doc/icons/pqAdvanced.svg");
- optionSettingPannel->addLargeAction(optionAct);
- }
- void MainWindow::createCategoryData(SARibbonCategory* page)
- {
- SARibbonPannel* dataPannel = page->addPannel(("dataBase"));
- QAction *materialDataAct = createAction(tr("材料数据库"),":/icon/doc/database.svg");
- dataPannel->addLargeAction(materialDataAct);
- QAction *gasDataAct = createAction(tr("气体数据库"),":/icon/doc/database.svg");
- dataPannel->addLargeAction(gasDataAct);
- QAction *probesDataAct = createAction(tr("探测器数据库"),":/icon/doc/database.svg");
- dataPannel->addLargeAction(probesDataAct);
- QAction *envirDataAct = createAction(tr("环境数据库"),":/icon/doc/database.svg");
- dataPannel->addLargeAction(envirDataAct);
- }
- void MainWindow::createCategoryGrid(SARibbonCategory* page)
- {
- SARibbonPannel* gridPannel = page->addPannel(("grid"));
- QAction *createFaceAct = createAction(tr("生成面网格"),":/icon/doc/icons/pqFaceMapData.svg");
- gridPannel->addLargeAction(createFaceAct);
- QAction *createCubicAct = createAction(tr("生成体网格"),":/icon/doc/icons/pqGhostCellsGenerator.svg");
- gridPannel->addLargeAction(createCubicAct);
- QAction *delGridAct = createAction(tr("删除网格"),":/icon/doc/icons/pqResetActorsPosition.svg");
- gridPannel->addLargeAction(delGridAct);
- QAction *gridInfoAct = createAction(tr("网格信息"),":/icon/doc/icons/pqEdgeCenterData.svg");
- gridPannel->addLargeAction(gridInfoAct);
- QAction *gridSegmentAct = createAction(tr("网格细分"),":/icon/doc/icons/pqClip.svg");
- gridPannel->addLargeAction(gridSegmentAct);
- SARibbonPannel* gridCheckPannel = page->addPannel(("grid Check"));
- QAction *gridCheckAct = createAction(tr("网格质量检查"),":/icon/doc/icons/pqFullscreen.svg");
- gridCheckPannel->addLargeAction(gridCheckAct);
- QAction *gridOptimisticAct = createAction(tr("网格质量优化"),":/icon/doc/icons/pqGlyph.svg");
- gridCheckPannel->addLargeAction(gridOptimisticAct);
- }
- void MainWindow::createCategoryHelp(SARibbonCategory* page)
- {
- SARibbonPannel* helpPannel = page->addPannel(("help Pannel"));
- QAction *operatManuals = createAction(tr("操作手册"),":/icon/doc/icons/pqMultiBlockData16.png");
- helpPannel->addLargeAction(operatManuals);
- QAction *licenseAct = createAction(tr("License"),":/icon/doc/cc-license.svg");
- helpPannel->addLargeAction(licenseAct);
- QAction *aboutAct = createAction(tr("关于软件"),":/icon/doc/icons/pqLightOn.svg");
- connect(aboutAct,&QAction::triggered,this,&MainWindow::onActionAboutTriggered);
- helpPannel->addLargeAction(aboutAct);
- }
- void MainWindow::onActionAboutTriggered()
- {
- QMessageBox::information(this,
- tr("about us:"),
- tr("\n ======================="
- "\n SARibbonBar version:0.9"
- "\n Author:南京航天航空大学"
- "\n Email:nuaa@163.com"
- "\n =======================")
- );
- }
- void MainWindow::createQuickAccessBar(SARibbonQuickAccessBar* quickAccessBar)
- {
- }
- void MainWindow::createRightButtonGroup(SARibbonButtonGroupWidget* rightBar)
- {
- }
- QAction* MainWindow::createAction(const QString& text, const QString& iconurl, const QString& objName)
- {
- QAction* act = new QAction(this);
- act->setText(text);
- act->setIcon(QIcon(iconurl));
- act->setObjectName(objName);
- return act;
- }
- QAction* MainWindow::createAction(const QString& text, const QString& iconurl)
- {
- QAction* act = new QAction(this);
- act->setText(text);
- act->setIcon(QIcon(iconurl));
- act->setObjectName(text);
- return act;
- }
- void MainWindow::addModelComplete()
- {
- mModelAdd->close();
- mStack->setCurrentIndex(1);
- }
|