author | John Kern <johnk@symbian.org> |
Fri, 28 Aug 2009 15:16:29 -0700 | |
changeset 0 | bbe0af256f1b |
child 1 | 8e9c5760ce6f |
permissions | -rwxr-xr-x |
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 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
4 |
#include "Document.h" |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
5 |
#include "mainwindow.h" |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
6 |
#include "ui_mainwindow.h" |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
7 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
8 |
MainWindow::MainWindow(QWidget *parent) |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
9 |
: QMainWindow(parent), ui(new Ui::MainWindow) |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
10 |
{ |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
11 |
ui->setupUi(this); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
12 |
// 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
|
13 |
workspace = new QWorkspace(); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
14 |
setCentralWidget(workspace); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
15 |
connect(workspace, SIGNAL(windowActivated(QWidget*)), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
16 |
this, SLOT(enableActions())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
17 |
mapper = new QSignalMapper(this); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
18 |
connect(mapper, SIGNAL(mapped(QWidget*)), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
19 |
workspace, SLOT(setActiveWindow(QWidget*))); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
20 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
21 |
this->createActions(); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
22 |
this->enableActions(); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
23 |
} |
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 |
MainWindow::~MainWindow() |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
26 |
{ |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
27 |
delete ui; |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
28 |
} |
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 |
void MainWindow::notYetImplemented() |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
31 |
{ |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
32 |
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
|
33 |
} |
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 |
void MainWindow::openLog() |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
36 |
{ |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
37 |
QString filename = QFileDialog::getOpenFileName( |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
38 |
this, tr("Open Log"), QDir::currentPath(), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
39 |
tr("Build log *.xml;;All files (*.*)")); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
40 |
Document *doc = new Document(this, filename); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
41 |
workspace->addWindow(doc); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
42 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
43 |
doc->show(); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
44 |
} |
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 |
void MainWindow::createActions() |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
47 |
{ |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
48 |
// file menu - mark as NYI |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
49 |
connect(ui->actionOpen, SIGNAL(triggered()), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
50 |
this, SLOT(openLog())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
51 |
connect(ui->actionClose, SIGNAL(triggered()), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
52 |
workspace, SLOT(closeActiveWindow())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
53 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
54 |
// find menu - mark as NYI |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
55 |
connect(ui->actionFind, SIGNAL(triggered()), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
56 |
this, SLOT(notYetImplemented())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
57 |
connect(ui->actionTags , SIGNAL(triggered()), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
58 |
this, SLOT(notYetImplemented())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
59 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
60 |
// window menu - mark as NYI |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
61 |
connect(ui->actionTile , SIGNAL(triggered()), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
62 |
this, SLOT(notYetImplemented())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
63 |
connect(ui->actionCascade , SIGNAL(triggered()), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
64 |
this, SLOT(notYetImplemented())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
65 |
connect(ui->actionNext_Window , SIGNAL(triggered()), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
66 |
this, SLOT(notYetImplemented())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
67 |
connect(ui->actionPrevious_Window , SIGNAL(triggered()), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
68 |
this, SLOT(notYetImplemented())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
69 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
70 |
ui->actionSeparator->setSeparator(true); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
71 |
} |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
72 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
73 |
void MainWindow::enableActions() |
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 |
bool hasDocuments = (activeDocument() != 0) ; |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
76 |
// file |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
77 |
ui->actionOpen->setEnabled(true); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
78 |
ui->actionClose->setEnabled(hasDocuments); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
79 |
ui->actionQuit->setEnabled(true); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
80 |
// find |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
81 |
ui->actionFind->setEnabled(hasDocuments); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
82 |
ui->actionTags->setEnabled(hasDocuments); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
83 |
// window |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
84 |
ui->actionCascade->setEnabled(hasDocuments); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
85 |
ui->actionTile->setEnabled(hasDocuments); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
86 |
ui->actionNext_Window->setEnabled(hasDocuments); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
87 |
ui->actionPrevious_Window->setEnabled(hasDocuments); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
88 |
ui->actionSeparator->setEnabled(hasDocuments); |
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 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
91 |
void MainWindow::updateWindowList() |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
92 |
{ |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
93 |
ui->menuWindow->clear(); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
94 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
95 |
ui->menuWindow->addAction(ui->actionTile); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
96 |
ui->menuWindow->addAction(ui->actionCascade); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
97 |
ui->menuWindow->addSeparator(); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
98 |
ui->menuWindow->addAction(ui->actionNext_Window); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
99 |
ui->menuWindow->addAction(ui->actionPrevious_Window); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
100 |
// 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
|
101 |
ui->menuWindow->addAction(ui->actionSeparator); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
102 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
103 |
int i=1; |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
104 |
foreach(QWidget *w, workspace->windowList()) |
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 |
QString text; |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
107 |
if ( i< 10) { |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
108 |
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
|
109 |
} else { |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
110 |
text = w->windowTitle(); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
111 |
} |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
112 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
113 |
QAction *action = ui->menuWindow->addAction(text); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
114 |
action->setCheckable(true); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
115 |
action->setChecked(w == activeDocument()); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
116 |
connect(action,SIGNAL(triggered()), |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
117 |
mapper, SLOT(map())); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
118 |
mapper->setMapping(action, w); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
119 |
} |
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 |
|
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
122 |
void MainWindow::closeEvent(QCloseEvent *event) |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
123 |
{ |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
124 |
workspace->closeAllWindows(); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
125 |
} |
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 |
Document * MainWindow::activeDocument() |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
128 |
{ |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
129 |
return qobject_cast<Document*>(workspace->activeWindow()); |
bbe0af256f1b
here is a demo which reads and displays xml.
John Kern <johnk@symbian.org>
parents:
diff
changeset
|
130 |
} |