launchpage.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. projectManager* pro = new projectManager();
  56. if(ui->openExample->isChecked())
  57. {
  58. pro->mName = mFileName.toStdString();
  59. pro->mPath = mFilePath.toStdString();
  60. pro->queryProject(pro->mId);
  61. }
  62. else if(ui->createExample->isChecked())
  63. {
  64. pro->mName = mSetName.toStdString();
  65. pro->mPath = mChosePath.toStdString();
  66. pro->createProject(pro->mId,pro->mName,pro->mDesc,pro->mPath);
  67. }
  68. MainWindow* w = new MainWindow();
  69. w->show();
  70. this->close();
  71. }
  72. else
  73. {
  74. QMessageBox mes(this);
  75. mes.warning(this,"warning","还未创建或打开算例",QDialogButtonBox::Ok,QDialogButtonBox::NoButton);
  76. }
  77. }
  78. void LaunchPage::on_openExample_toggled(bool checked)
  79. {
  80. if(checked)
  81. {
  82. mOpenDialog = new QFileDialog(this);
  83. mOpenDialog->setModal(QFileDialog::ExistingFile);
  84. QString FileName = mOpenDialog->getOpenFileName(this,"打开算例","./","ALL(*.*)、Images(*.png *.jpg)、CPP文件(*.cpp)");
  85. int temp = FileName.lastIndexOf("/");
  86. mFileName = FileName.right(FileName.length()-temp-1);
  87. mFilePath = FileName.left(temp+1);
  88. ui->readName->setText(mFileName);
  89. ui->readPath->setText(mFilePath);
  90. if(!mFileName.isEmpty() && !mFilePath.isEmpty())
  91. {
  92. ui->openLabel1->show();
  93. ui->openLabel2->show();
  94. ui->readName->show();
  95. ui->readPath->show();
  96. }
  97. else
  98. {
  99. ui->createExample ->setChecked(true);
  100. }
  101. }
  102. else
  103. {
  104. ui->openLabel1->hide();
  105. ui->openLabel2->hide();
  106. ui->readName->hide();
  107. ui->readPath->hide();
  108. ui->setName->show();
  109. ui->setPath->show();
  110. ui->browseButton->show();
  111. ui->label->show();
  112. ui->label_2->show();
  113. }
  114. }
  115. void LaunchPage::on_browseButton_clicked()
  116. {
  117. mViewDialog = new QFileDialog(this);
  118. mChosePath = mViewDialog->getExistingDirectory(this,"浏览","./");
  119. ui->setPath->setText(mChosePath);
  120. }
  121. void LaunchPage::on_createExample_toggled(bool checked)
  122. {
  123. if(checked)
  124. {
  125. ui->openLabel1->hide();
  126. ui->openLabel2->hide();
  127. ui->readName->hide();
  128. ui->readPath->hide();
  129. }
  130. else
  131. {
  132. ui->setName->hide();
  133. ui->setPath->hide();
  134. ui->browseButton->hide();
  135. ui->label->hide();
  136. ui->label_2->hide();
  137. }
  138. }