123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- #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();
- //菜单栏
- 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("background");
- mStack->addWidget(page0);
- QLabel* page1 = new QLabel("model");
- mStack->addWidget(page1);
- 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* pannelFile = page->addPannel(("File Operator"));
- QAction *actOutput = createAction(tr("导入"),":/icon/doc/icons/min.png");
- pannelFile->addLargeAction(actOutput);
- QAction *actInput = createAction(tr("导出"),":/icon/doc/icons/add.png");
- pannelFile->addLargeAction(actInput);
- }
- void MainWindow::createCategoryDisplay(SARibbonCategory* page)
- {
- }
- void MainWindow::createCategoryData(SARibbonCategory* page)
- {
- }
- void MainWindow::createCategoryGrid(SARibbonCategory* page)
- {
- }
- void MainWindow::createCategoryHelp(SARibbonCategory* page)
- {
- }
- 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;
- }
|