#include <QtCore/QLibraryInfo>
#include <QtGui/QApplication>
#include <QtGui/QAction>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QMessageBox>
#include "mainwindow.h"
#include "findfiledialog.h"
#include "assistant.h"
#include "textedit.h"
MainWindow::MainWindow()
{
assistant = new Assistant;
textViewer = new TextEdit;
textViewer->setContents(QLibraryInfo::location(QLibraryInfo::ExamplesPath)
+ QLatin1String("/help/simpletextviewer/documentation/intro.html"));
setCentralWidget(textViewer);
createActions();
createMenus();
setWindowTitle(tr("Simple Text Viewer"));
resize(750, 400);
}
void MainWindow::closeEvent(QCloseEvent *)
{
delete assistant;
}
void MainWindow::about()
{
QMessageBox::about(this, tr("About Simple Text Viewer"),
tr("This example demonstrates how to use\n"
"Qt Assistant as help system for your\n"
"own application."));
}
void MainWindow::showDocumentation()
{
assistant->showDocumentation("index.html");
}
void MainWindow::open()
{
FindFileDialog dialog(textViewer, assistant);
dialog.exec();
}
void MainWindow::createActions()
{
assistantAct = new QAction(tr("Help Contents"), this);
assistantAct->setShortcut(QKeySequence::HelpContents);
connect(assistantAct, SIGNAL(triggered()), this, SLOT(showDocumentation()));
openAct = new QAction(tr("&Open..."), this);
openAct->setShortcut(QKeySequence::Open);
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
clearAct = new QAction(tr("&Clear"), this);
clearAct->setShortcut(tr("Ctrl+C"));
connect(clearAct, SIGNAL(triggered()), textViewer, SLOT(clear()));
exitAct = new QAction(tr("E&xit"), this);
exitAct->setShortcuts(QKeySequence::Quit);
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
aboutAct = new QAction(tr("&About"), this);
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
aboutQtAct = new QAction(tr("About &Qt"), this);
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
void MainWindow::createMenus()
{
fileMenu = new QMenu(tr("&File"), this);
fileMenu->addAction(openAct);
fileMenu->addAction(clearAct);
fileMenu->addSeparator();
fileMenu->addAction(exitAct);
helpMenu = new QMenu(tr("&Help"), this);
helpMenu->addAction(assistantAct);
helpMenu->addSeparator();
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
menuBar()->addMenu(fileMenu);
menuBar()->addMenu(helpMenu);
}