launchpage.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/min.png"));
  12. QString imageFile(":/icon/doc/icons/add.png");
  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( //正常状态样式
  23. "QPushButton{"
  24. "background-color:rgba(0,191,255,50);"//背景色(也可以设置图片)
  25. "border-style:outset;" //边框样式(inset/outset)
  26. "border-width:4px;" //边框宽度像素
  27. "border-radius:10px;" //边框圆角半径像素
  28. "border-color:rgba(255,255,255,0);" //边框颜色
  29. // "font:bold 15px;" //字体,字体大小
  30. // "color:rgba(0,0,0,255);" //字体颜色
  31. "padding:7px;" //填衬
  32. "}"
  33. //鼠标按下样式
  34. "QPushButton:pressed{"
  35. "background-color:rgba(100,255,100,100);"
  36. "border-color:rgba(255,255,255,200);"
  37. "color:rgba(0,0,0,255);"
  38. "}"
  39. //界面背景色
  40. "QMainWindow{"
  41. "background-color:rgba(255,255,255,255);"
  42. "}"
  43. );
  44. connect(ui->cancelButton,&QPushButton::clicked,this,&QMainWindow::close);
  45. }
  46. LaunchPage::~LaunchPage()
  47. {
  48. delete ui;
  49. }
  50. void LaunchPage::on_confirmButton_clicked()
  51. {
  52. mSetName = ui->setName->text();
  53. if((!mSetName.isEmpty() && !mChosePath.isEmpty() )||(ui->openExample->isChecked()&& !mFileName.isEmpty() && !mFilePath.isEmpty()))
  54. {
  55. MainWindow* w = new MainWindow();
  56. w->show();
  57. this->close();
  58. }
  59. else
  60. {
  61. QMessageBox mes(this);
  62. mes.warning(this,"warning","还未创建或打开算例",QDialogButtonBox::Ok,QDialogButtonBox::NoButton);
  63. }
  64. }
  65. void LaunchPage::on_openExample_toggled(bool checked)
  66. {
  67. if(checked)
  68. {
  69. mOpenDialog = new QFileDialog(this);
  70. mOpenDialog->setModal(QFileDialog::ExistingFile);
  71. QString FileName = mOpenDialog->getOpenFileName(this,"打开算例","./","ALL(*.*)、Images(*.png *.jpg)、CPP文件(*.cpp)");
  72. int temp = FileName.lastIndexOf("/");
  73. mFileName = FileName.right(FileName.length()-temp-1);
  74. mFilePath = FileName.left(temp+1);
  75. ui->readName->setText(mFileName);
  76. ui->readPath->setText(mFilePath);
  77. if(!mFileName.isEmpty() && !mFilePath.isEmpty())
  78. {
  79. ui->openLabel1->show();
  80. ui->openLabel2->show();
  81. ui->readName->show();
  82. ui->readPath->show();
  83. }
  84. else
  85. {
  86. ui->createExample ->setChecked(true);
  87. }
  88. }
  89. else
  90. {
  91. ui->openLabel1->hide();
  92. ui->openLabel2->hide();
  93. ui->readName->hide();
  94. ui->readPath->hide();
  95. ui->setName->show();
  96. ui->setPath->show();
  97. ui->browseButton->show();
  98. ui->label->show();
  99. ui->label_2->show();
  100. }
  101. }
  102. void LaunchPage::on_browseButton_clicked()
  103. {
  104. mViewDialog = new QFileDialog(this);
  105. mChosePath = mViewDialog->getExistingDirectory(this,"浏览","./");
  106. ui->setPath->setText(mChosePath);
  107. }
  108. void LaunchPage::on_createExample_toggled(bool checked)
  109. {
  110. if(checked)
  111. {
  112. ui->openLabel1->hide();
  113. ui->openLabel2->hide();
  114. ui->readName->hide();
  115. ui->readPath->hide();
  116. }
  117. else
  118. {
  119. ui->setName->hide();
  120. ui->setPath->hide();
  121. ui->browseButton->hide();
  122. ui->label->hide();
  123. ui->label_2->hide();
  124. }
  125. }