Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions

mainwindow.cpp Example File
help/simpletextviewer/mainwindow.cpp

 /****************************************************************************
 **
 ** Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
 **
 ** This file is part of the documentation of the Qt Toolkit.
 **
 ** Licensees holding a valid Qt License Agreement may use this file in
 ** accordance with the rights, responsibilities and obligations
 ** contained therein.  Please consult your licensing agreement or
 ** contact [email protected] if any conditions of this licensing
 ** agreement are not clear to you.
 **
 ** Further information about Qt licensing is available at:
 ** http://trolltech.com/products/appdev/licensing.
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ****************************************************************************/

 #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"

 // ![0]
 MainWindow::MainWindow()
 {
     assistant = new Assistant;
 // ![0]
     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);
 // ![1]
 }

 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(tr("F1"));
     connect(assistantAct, SIGNAL(triggered()), this, SLOT(showDocumentation()));

     openAct = new QAction(tr("&Open..."), this);
     openAct->setShortcut(tr("Ctrl+O"));
     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->setShortcut(tr("Ctrl+Q"));
     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);
 }


Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.4.3