source: trunk/examples/assistant/simpletextviewer/mainwindow.cpp@ 92

Last change on this file since 92 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 4.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtGui>
43
44#include "mainwindow.h"
45#include "findfiledialog.h"
46
47//! [0]
48MainWindow::MainWindow()
49{
50 textViewer = new QTextEdit;
51 textViewer->setReadOnly(true);
52 QFile file("documentation/intro.html");
53 if (file.open(QIODevice::ReadOnly))
54 textViewer->setHtml(file.readAll());
55
56 setCentralWidget(textViewer);
57
58 createActions();
59 createMenus();
60
61 initializeAssistant();
62
63 setWindowTitle(tr("Simple Text Viewer"));
64 resize(750, 400);
65}
66//! [0]
67
68//! [1]
69void MainWindow::closeEvent(QCloseEvent *)
70{
71 if (assistantClient)
72 assistantClient->closeAssistant();
73}
74//! [1]
75
76void MainWindow::about()
77{
78 QMessageBox::about(this, tr("About Simple Text Viewer"),
79 tr("This example demonstrates how to use\n" \
80 "Qt Assistant as help system for your\n" \
81 "own application."));
82}
83
84//! [2]
85void MainWindow::assistant()
86{
87 assistantClient->showPage(QLibraryInfo::location(QLibraryInfo::ExamplesPath) +
88 QDir::separator() +
89 "assistant/simpletextviewer/documentation/index.html");
90}
91//! [2]
92
93//! [3]
94void MainWindow::open()
95{
96 FindFileDialog dialog(textViewer, assistantClient);
97 dialog.exec();
98}
99//! [3]
100
101void MainWindow::createActions()
102{
103 assistantAct = new QAction(tr("Help Contents"), this);
104 assistantAct->setShortcut(tr("F1"));
105 connect(assistantAct, SIGNAL(triggered()), this, SLOT(assistant()));
106
107 openAct = new QAction(tr("&Open..."), this);
108 openAct->setShortcut(tr("Ctrl+O"));
109 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
110
111 clearAct = new QAction(tr("&Clear"), this);
112 clearAct->setShortcut(tr("Ctrl+C"));
113 connect(clearAct, SIGNAL(triggered()), textViewer, SLOT(clear()));
114
115 exitAct = new QAction(tr("E&xit"), this);
116 exitAct->setShortcut(tr("Ctrl+Q"));
117 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
118
119 aboutAct = new QAction(tr("&About"), this);
120 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
121
122 aboutQtAct = new QAction(tr("About &Qt"), this);
123 connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
124}
125
126void MainWindow::createMenus()
127{
128 fileMenu = new QMenu(tr("&File"), this);
129 fileMenu->addAction(openAct);
130 fileMenu->addAction(clearAct);
131 fileMenu->addSeparator();
132 fileMenu->addAction(exitAct);
133
134 helpMenu = new QMenu(tr("&Help"), this);
135 helpMenu->addAction(assistantAct);
136 helpMenu->addSeparator();
137 helpMenu->addAction(aboutAct);
138 helpMenu->addAction(aboutQtAct);
139
140
141 menuBar()->addMenu(fileMenu);
142 menuBar()->addMenu(helpMenu);
143}
144
145//! [4]
146void MainWindow::initializeAssistant()
147{
148 assistantClient = new QAssistantClient(QLibraryInfo::location(QLibraryInfo::BinariesPath), this);
149
150 QStringList arguments;
151 arguments << "-profile" << QString("documentation") + QDir::separator() + QString("simpletextviewer.adp");
152 assistantClient->setArguments(arguments);
153}
154//! [4]
Note: See TracBrowser for help on using the repository browser.