text: #include "mainwindow.h"
  #include "ui_mainwindow.h"
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui->setupUi(this);
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void MainWindow::on_quitButton_clicked()
  {
      qApp->quit();
  }
  
  void MainWindow::on_optionsButton_clicked()
  {
      OptionsWindow* optionsWindow = new OptionsWindow(this);
      optionsWindow->setModal(true);
      optionsWindow->exec();
  }
  
  void MainWindow::on_loadButton_clicked()
  {
      QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QString(),
                 tr("Text Files (*.txt);;C++ Files (*.cpp *.h)"));
  
         if (!fileName.isEmpty()) {
             QFile file(fileName);
             if (!file.open(QIODevice::ReadOnly)) {
                 QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
                 return;
             }
             QTextStream in(&file);
             ui->plainTextEdit->document()->setPlainText(in.readAll());
  
             file.close();
         }
  }
  
  void MainWindow::on_saveButton_clicked()
  {
      QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QString(),
                  tr("Text Files (*.txt);;C++ Files (*.cpp *.h)"));
  
          if (!fileName.isEmpty()) {
              QFile file(fileName);
              if (!file.open(QIODevice::WriteOnly)) {
                  // error message
              } else {
                  QTextStream stream(&file);
                  stream << ui->plainTextEdit->toPlainText();
                  stream.flush();
                  file.close();
              }
          }
  }
  