launchpage.cpp 3.4 KB

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