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