main_window.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "qt/input/main_window.hpp"
  2. QtMainWindow::QtMainWindow():QMainWindow(){
  3. input=nullptr;
  4. new_act=new QAction("New input",this);
  5. load_act=new QAction("Load input",this);
  6. exit_act=new QAction("Exit",this);
  7. //Menu bar
  8. input_menu=menuBar()->addMenu("File");
  9. input_menu->addAction(new_act);
  10. input_menu->addAction(load_act);
  11. input_menu->addAction(exit_act);
  12. connect(new_act,&QAction::triggered,this,&QtMainWindow::new_input);
  13. connect(load_act,&QAction::triggered,this,&QtMainWindow::load_input);
  14. connect(exit_act,&QAction::triggered,this,&QtMainWindow::exit);
  15. }
  16. void
  17. QtMainWindow::new_input(){
  18. input=new QtInput;
  19. setCentralWidget(input);
  20. connect(input,&QtInput::exit_signal,this,&QtMainWindow::exit_input);
  21. }
  22. void
  23. QtMainWindow::load_input(){
  24. QString filename=QFileDialog::getOpenFileName(this,"Load input","inputs/","QT input file (*.input)");
  25. input=new QtInput(filename);
  26. setCentralWidget(input);
  27. connect(input,&QtInput::exit_signal,this,&QtMainWindow::exit_input);
  28. new_act->setEnabled(false);
  29. load_act->setEnabled(false);
  30. }
  31. void
  32. QtMainWindow::exit_input(){
  33. disconnect(input,nullptr,nullptr,nullptr);
  34. delete input;
  35. input=nullptr;
  36. setCentralWidget(nullptr);
  37. new_act->setEnabled(true);
  38. load_act->setEnabled(true);
  39. }
  40. void
  41. QtMainWindow::exit(){
  42. QApplication::quit();
  43. }