BuildLogViewer/mainwindow.cpp
changeset 41 b56d7e268634
parent 40 edc0144719a1
child 42 b9716e8867f1
equal deleted inserted replaced
40:edc0144719a1 41:b56d7e268634
     1 #include <QFileDialog>
       
     2 #include <QMessageBox>
       
     3 
       
     4 #include "AtAGlance.h"
       
     5 #include "Document.h"
       
     6 #include "mainwindow.h"
       
     7 #include "ui_mainwindow.h"
       
     8 
       
     9 MainWindow::MainWindow(QWidget *parent)
       
    10     : QMainWindow(parent), ui(new Ui::MainWindow)
       
    11 {
       
    12     ui->setupUi(this);
       
    13     // MDI from Chap 4, page 105 Foundamentals of Qt Development
       
    14     workspace = new QWorkspace();
       
    15     setCentralWidget(workspace);
       
    16     connect(workspace, SIGNAL(windowActivated(QWidget*)),
       
    17             this, SLOT(enableActions()));
       
    18     mapper = new QSignalMapper(this);
       
    19     connect(mapper, SIGNAL(mapped(QWidget*)),
       
    20             workspace, SLOT(setActiveWindow(QWidget*)));
       
    21 
       
    22     this->createActions();
       
    23     this->enableActions();
       
    24 }
       
    25 
       
    26 MainWindow::~MainWindow()
       
    27 {
       
    28     delete ui;
       
    29 }
       
    30 
       
    31 void MainWindow::notYetImplemented()
       
    32 {
       
    33     QMessageBox::information(this, tr("Build Log Viewer"), tr("Not Yet Implemented."));
       
    34 }
       
    35 
       
    36  void MainWindow::openLog()
       
    37  {
       
    38     QString filename = QFileDialog::getOpenFileName(
       
    39              this, tr("Open Log"), QDir::currentPath(),
       
    40              tr("Build log *.xml;;All files (*.*)"));
       
    41     Document *doc = new Document(this, filename);
       
    42     workspace->addWindow(doc);
       
    43 
       
    44     doc->show();
       
    45  }
       
    46 
       
    47  void MainWindow::showStatus()
       
    48  {
       
    49     QString filename = QFileDialog::getOpenFileName(
       
    50         this, tr("Open Log"), QDir::currentPath(),
       
    51         tr("Build log *.xml;;All files (*.*)"));
       
    52     AtAGlance *aag = new AtAGlance(filename, this);
       
    53     workspace->addWindow(aag);
       
    54     aag->traveAndPopulate();
       
    55     // obsolete using BuildResults.ui now.
       
    56     // aag->decideOnLayout();
       
    57     aag->show();
       
    58  }
       
    59 
       
    60  void MainWindow::createActions()
       
    61  {
       
    62     // file menu - mark as NYI
       
    63     //connect(ui->actionOpen, SIGNAL(triggered()),
       
    64     //      this, SLOT(openLog()));
       
    65     connect(ui->actionOpen, SIGNAL(triggered()),
       
    66             this, SLOT(showStatus()));
       
    67     connect(ui->actionClose, SIGNAL(triggered()),
       
    68             workspace, SLOT(closeActiveWindow()));
       
    69 
       
    70     // find menu - mark as NYI
       
    71     connect(ui->actionFind, SIGNAL(triggered()),
       
    72             this, SLOT(notYetImplemented()));
       
    73     connect(ui->actionTags , SIGNAL(triggered()),
       
    74             this, SLOT(notYetImplemented()));
       
    75 
       
    76     // window menu - mark as NYI
       
    77     connect(ui->actionTile , SIGNAL(triggered()),
       
    78         this, SLOT(notYetImplemented()));
       
    79     connect(ui->actionCascade , SIGNAL(triggered()),
       
    80         this, SLOT(notYetImplemented()));
       
    81     connect(ui->actionNext_Window , SIGNAL(triggered()),
       
    82         this, SLOT(notYetImplemented()));
       
    83     connect(ui->actionPrevious_Window , SIGNAL(triggered()),
       
    84         this, SLOT(notYetImplemented()));
       
    85 
       
    86     ui->actionSeparator->setSeparator(true);
       
    87  }
       
    88 
       
    89  void MainWindow::enableActions()
       
    90  {
       
    91      bool hasDocuments = (activeDocument() != 0) ;
       
    92      // file
       
    93      ui->actionOpen->setEnabled(true);
       
    94      ui->actionClose->setEnabled(hasDocuments);
       
    95      ui->actionQuit->setEnabled(true);
       
    96      // find
       
    97      ui->actionFind->setEnabled(hasDocuments);
       
    98      ui->actionTags->setEnabled(hasDocuments);
       
    99      // window
       
   100      ui->actionCascade->setEnabled(hasDocuments);
       
   101      ui->actionTile->setEnabled(hasDocuments);
       
   102      ui->actionNext_Window->setEnabled(hasDocuments);
       
   103      ui->actionPrevious_Window->setEnabled(hasDocuments);
       
   104      ui->actionSeparator->setEnabled(hasDocuments);
       
   105  }
       
   106 
       
   107  void MainWindow::updateWindowList()
       
   108  {
       
   109      ui->menuWindow->clear();
       
   110 
       
   111      ui->menuWindow->addAction(ui->actionTile);
       
   112      ui->menuWindow->addAction(ui->actionCascade);
       
   113      ui->menuWindow->addSeparator();
       
   114      ui->menuWindow->addAction(ui->actionNext_Window);
       
   115      ui->menuWindow->addAction(ui->actionPrevious_Window);
       
   116      // If there are no open logs, we will disable this one.
       
   117      ui->menuWindow->addAction(ui->actionSeparator);
       
   118 
       
   119      int i=1;
       
   120      foreach(QWidget *w, workspace->windowList())
       
   121      {
       
   122           QString text;
       
   123           if ( i< 10) {
       
   124               text = QString("&%1 %2").arg(i++).arg(w->windowTitle());
       
   125           } else {
       
   126               text = w->windowTitle();
       
   127           }
       
   128 
       
   129           QAction *action = ui->menuWindow->addAction(text);
       
   130           action->setCheckable(true);
       
   131           action->setChecked(w == activeDocument());
       
   132           connect(action,SIGNAL(triggered()),
       
   133                   mapper, SLOT(map()));
       
   134           mapper->setMapping(action, w);
       
   135       }
       
   136  }
       
   137 
       
   138 void MainWindow::closeEvent(QCloseEvent *event)
       
   139 {
       
   140     workspace->closeAllWindows();
       
   141 }
       
   142 
       
   143 Document * MainWindow::activeDocument()
       
   144 {
       
   145     return qobject_cast<Document*>(workspace->activeWindow());
       
   146 }