launchpage.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "launchpage.h"
  2. LaunchPage::LaunchPage(QWidget *parent) :
  3. QMainWindow(parent),
  4. ui(new Ui::LaunchPage)
  5. {
  6. mPro = new projectManager;
  7. ui->setupUi(this);
  8. setWindowTitle("启动页");
  9. setWindowIcon(QIcon(":/icon/doc/icons/pvIcon.svg"));
  10. QString imageFile(":/icon/doc/icons/pvIcon.svg");
  11. QImage *image = new QImage;
  12. if(!(image->load(imageFile)))
  13. {
  14. std::cout << "load image error!!!"<< std::endl;
  15. delete image;
  16. return;
  17. }
  18. ui->imagelabel->setPixmap(QPixmap::fromImage(*image));
  19. ui->createExample->setChecked(true);
  20. onCreateExampleToggled(true);
  21. setStyleSheet(lanchStyle);
  22. connect(ui->cancelButton,&QPushButton::clicked,this,&QMainWindow::close);
  23. connect(ui->confirmButton,&QPushButton::clicked,this,&LaunchPage::onConfirmButtonClicked);
  24. connect(ui->openExample,&QRadioButton::toggled,this,&LaunchPage::onOpenExampleToggled);
  25. connect(ui->browseButton,&QPushButton::clicked,this,&LaunchPage::onBrowseButtonClicked);
  26. connect(ui->createExample,&QRadioButton::toggled,this,&LaunchPage::onCreateExampleToggled);
  27. }
  28. LaunchPage::~LaunchPage()
  29. {
  30. delete ui;
  31. }
  32. void LaunchPage::onConfirmButtonClicked()
  33. {
  34. mSetName = ui->setName->text();
  35. if((!mSetName.isEmpty() && !mChosePath.isEmpty() )||(ui->openExample->isChecked()&& !mFileName.isEmpty() && !mFilePath.isEmpty()))
  36. {
  37. if(ui->openExample->isChecked())
  38. {
  39. mPro->mProjectInfo.name = mFileName.toStdString();
  40. mPro->mProjectInfo.path = mFilePath.toStdString();
  41. }
  42. else if(ui->createExample->isChecked())
  43. {
  44. mPro->mProjectInfo.name = mSetName.toStdString();
  45. mPro->mProjectInfo.path = mChosePath.toStdString();
  46. // mPro->createProject();
  47. }
  48. MainWindow * m = new MainWindow;
  49. m->show();
  50. this->close();
  51. }
  52. else
  53. {
  54. QMessageBox mes(this);
  55. mes.warning(this,"warning","还未创建或打开算例",QDialogButtonBox::Ok,QDialogButtonBox::NoButton);
  56. }
  57. }
  58. void LaunchPage::onOpenExampleToggled(bool checked)
  59. {
  60. if(checked)
  61. {
  62. mOpenDialog = new QFileDialog(this);
  63. mOpenDialog->setModal(QFileDialog::ExistingFile);
  64. QString FileName = mOpenDialog->getOpenFileName(this,"打开算例","./","ALL(*.*)、Images(*.png *.jpg)、CPP文件(*.cpp)");
  65. int temp = FileName.lastIndexOf("/");
  66. mFileName = FileName.right(FileName.length()-temp-1);
  67. mFilePath = FileName.left(temp+1);
  68. ui->readName->setText(mFileName);
  69. ui->readPath->setText(mFilePath);
  70. if(!mFileName.isEmpty() && !mFilePath.isEmpty())
  71. {
  72. ui->openLabel1->show();
  73. ui->openLabel2->show();
  74. ui->readName->show();
  75. ui->readPath->show();
  76. }
  77. else
  78. {
  79. ui->createExample ->setChecked(true);
  80. }
  81. }
  82. else
  83. {
  84. ui->openLabel1->hide();
  85. ui->openLabel2->hide();
  86. ui->readName->hide();
  87. ui->readPath->hide();
  88. ui->setName->show();
  89. ui->setPath->show();
  90. ui->browseButton->show();
  91. ui->label->show();
  92. ui->label_2->show();
  93. }
  94. }
  95. void LaunchPage::onBrowseButtonClicked()
  96. {
  97. mViewDialog = new QFileDialog(this);
  98. mChosePath = mViewDialog->getExistingDirectory(this,"浏览","./");
  99. ui->setPath->setText(mChosePath);
  100. }
  101. void LaunchPage::onCreateExampleToggled(bool checked)
  102. {
  103. if(checked)
  104. {
  105. ui->openLabel1->hide();
  106. ui->openLabel2->hide();
  107. ui->readName->hide();
  108. ui->readPath->hide();
  109. }
  110. else
  111. {
  112. ui->setName->hide();
  113. ui->setPath->hide();
  114. ui->browseButton->hide();
  115. ui->label->hide();
  116. ui->label_2->hide();
  117. }
  118. }