examples/assistant/simpletextviewer/mainwindow.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the examples of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QtGui>
       
    43 
       
    44 #include "mainwindow.h"
       
    45 #include "findfiledialog.h"
       
    46 
       
    47 //! [0]
       
    48 MainWindow::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]
       
    69 void MainWindow::closeEvent(QCloseEvent *)
       
    70 {
       
    71     if (assistantClient)
       
    72         assistantClient->closeAssistant();
       
    73 }
       
    74 //! [1]
       
    75 
       
    76 void 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]
       
    85 void 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]
       
    94 void MainWindow::open()
       
    95 {
       
    96     FindFileDialog dialog(textViewer, assistantClient);
       
    97     dialog.exec();
       
    98 }
       
    99 //! [3]
       
   100 
       
   101 void MainWindow::createActions()
       
   102 {
       
   103     assistantAct = new QAction(tr("Help Contents"), this);
       
   104     assistantAct->setShortcuts(QKeySequence::HelpContents);
       
   105     connect(assistantAct, SIGNAL(triggered()), this, SLOT(assistant()));
       
   106 
       
   107     openAct = new QAction(tr("&Open..."), this);
       
   108     openAct->setShortcuts(QKeySequence::Open);
       
   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->setShortcuts(QKeySequence::Quit);
       
   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 
       
   126 void 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]
       
   146 void 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]