#include "launchpage.h" #include "mainwindow.h" #include "ui_launchpage.h" #include LaunchPage::LaunchPage(QWidget *parent) : QMainWindow(parent), ui(new Ui::LaunchPage) { ui->setupUi(this); setWindowTitle("启动页"); setWindowIcon(QIcon(":/icon/doc/icons/min.png")); QString imageFile(":/icon/doc/icons/add.png"); QImage *image = new QImage; if(!(image->load(imageFile))) { std::cout << "load image error!!!"<< std::endl; delete image; return; } ui->imagelabel->setPixmap(QPixmap::fromImage(*image)); ui->createExample ->setChecked(true); setStyleSheet(lanchStyle); connect(ui->cancelButton,&QPushButton::clicked,this,&QMainWindow::close); } LaunchPage::~LaunchPage() { delete ui; } void LaunchPage::on_confirmButton_clicked() { mSetName = ui->setName->text(); if((!mSetName.isEmpty() && !mChosePath.isEmpty() )||(ui->openExample->isChecked()&& !mFileName.isEmpty() && !mFilePath.isEmpty())) { projectManager* pro = new projectManager(); if(ui->openExample->isChecked()) { pro->mName = mFileName.toStdString(); pro->mPath = mFilePath.toStdString(); pro->queryProject(pro->mId); } else if(ui->createExample->isChecked()) { pro->mName = mSetName.toStdString(); pro->mPath = mChosePath.toStdString(); pro->createProject(pro->mId,pro->mName,pro->mDesc,pro->mPath); } MainWindow* w = new MainWindow(); w->show(); this->close(); } else { QMessageBox mes(this); mes.warning(this,"warning","还未创建或打开算例",QDialogButtonBox::Ok,QDialogButtonBox::NoButton); } } void LaunchPage::on_openExample_toggled(bool checked) { if(checked) { mOpenDialog = new QFileDialog(this); mOpenDialog->setModal(QFileDialog::ExistingFile); QString FileName = mOpenDialog->getOpenFileName(this,"打开算例","./","ALL(*.*)、Images(*.png *.jpg)、CPP文件(*.cpp)"); int temp = FileName.lastIndexOf("/"); mFileName = FileName.right(FileName.length()-temp-1); mFilePath = FileName.left(temp+1); ui->readName->setText(mFileName); ui->readPath->setText(mFilePath); if(!mFileName.isEmpty() && !mFilePath.isEmpty()) { ui->openLabel1->show(); ui->openLabel2->show(); ui->readName->show(); ui->readPath->show(); } else { ui->createExample ->setChecked(true); } } else { ui->openLabel1->hide(); ui->openLabel2->hide(); ui->readName->hide(); ui->readPath->hide(); ui->setName->show(); ui->setPath->show(); ui->browseButton->show(); ui->label->show(); ui->label_2->show(); } } void LaunchPage::on_browseButton_clicked() { mViewDialog = new QFileDialog(this); mChosePath = mViewDialog->getExistingDirectory(this,"浏览","./"); ui->setPath->setText(mChosePath); } void LaunchPage::on_createExample_toggled(bool checked) { if(checked) { ui->openLabel1->hide(); ui->openLabel2->hide(); ui->readName->hide(); ui->readPath->hide(); } else { ui->setName->hide(); ui->setPath->hide(); ui->browseButton->hide(); ui->label->hide(); ui->label_2->hide(); } }