From 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 23 Mar 2009 10:34:13 +0100 Subject: Long live Qt! --- examples/assistant/README | 38 ++++ examples/assistant/assistant.pro | 8 + .../simpletextviewer/documentation/about.txt | 9 + .../simpletextviewer/documentation/browse.html | 34 ++++ .../simpletextviewer/documentation/filedialog.html | 48 +++++ .../simpletextviewer/documentation/findfile.html | 32 +++ .../documentation/images/browse.png | Bin 0 -> 21553 bytes .../documentation/images/fadedfilemenu.png | Bin 0 -> 9589 bytes .../documentation/images/filedialog.png | Bin 0 -> 12318 bytes .../documentation/images/handbook.png | Bin 0 -> 1060 bytes .../documentation/images/mainwindow.png | Bin 0 -> 12769 bytes .../simpletextviewer/documentation/images/open.png | Bin 0 -> 11697 bytes .../documentation/images/wildcard.png | Bin 0 -> 11266 bytes .../simpletextviewer/documentation/index.html | 41 ++++ .../simpletextviewer/documentation/intro.html | 28 +++ .../simpletextviewer/documentation/openfile.html | 36 ++++ .../documentation/simpletextviewer.adp | 40 ++++ .../documentation/wildcardmatching.html | 57 ++++++ .../assistant/simpletextviewer/findfiledialog.cpp | 221 +++++++++++++++++++++ .../assistant/simpletextviewer/findfiledialog.h | 99 +++++++++ examples/assistant/simpletextviewer/main.cpp | 52 +++++ examples/assistant/simpletextviewer/mainwindow.cpp | 154 ++++++++++++++ examples/assistant/simpletextviewer/mainwindow.h | 91 +++++++++ .../simpletextviewer/simpletextviewer.pro | 16 ++ 24 files changed, 1004 insertions(+) create mode 100644 examples/assistant/README create mode 100644 examples/assistant/assistant.pro create mode 100644 examples/assistant/simpletextviewer/documentation/about.txt create mode 100644 examples/assistant/simpletextviewer/documentation/browse.html create mode 100644 examples/assistant/simpletextviewer/documentation/filedialog.html create mode 100644 examples/assistant/simpletextviewer/documentation/findfile.html create mode 100644 examples/assistant/simpletextviewer/documentation/images/browse.png create mode 100644 examples/assistant/simpletextviewer/documentation/images/fadedfilemenu.png create mode 100644 examples/assistant/simpletextviewer/documentation/images/filedialog.png create mode 100644 examples/assistant/simpletextviewer/documentation/images/handbook.png create mode 100644 examples/assistant/simpletextviewer/documentation/images/mainwindow.png create mode 100644 examples/assistant/simpletextviewer/documentation/images/open.png create mode 100644 examples/assistant/simpletextviewer/documentation/images/wildcard.png create mode 100644 examples/assistant/simpletextviewer/documentation/index.html create mode 100644 examples/assistant/simpletextviewer/documentation/intro.html create mode 100644 examples/assistant/simpletextviewer/documentation/openfile.html create mode 100644 examples/assistant/simpletextviewer/documentation/simpletextviewer.adp create mode 100644 examples/assistant/simpletextviewer/documentation/wildcardmatching.html create mode 100644 examples/assistant/simpletextviewer/findfiledialog.cpp create mode 100644 examples/assistant/simpletextviewer/findfiledialog.h create mode 100644 examples/assistant/simpletextviewer/main.cpp create mode 100644 examples/assistant/simpletextviewer/mainwindow.cpp create mode 100644 examples/assistant/simpletextviewer/mainwindow.h create mode 100644 examples/assistant/simpletextviewer/simpletextviewer.pro (limited to 'examples/assistant') diff --git a/examples/assistant/README b/examples/assistant/README new file mode 100644 index 0000000000..85f5a4373d --- /dev/null +++ b/examples/assistant/README @@ -0,0 +1,38 @@ +Support for interactive help is provided by the Qt Assistant application. +Developers can take advantages of the facilities it offers to display +specially-prepared documentation to users of their applications. + + +The example launcher provided with Qt can be used to explore each of the +examples in this directory. + +Documentation for these examples can be found via the Tutorial and Examples +link in the main Qt documentation. + + +Finding the Qt Examples and Demos launcher +========================================== + +On Windows: + +The launcher can be accessed via the Windows Start menu. Select the menu +entry entitled "Qt Examples and Demos" entry in the submenu containing +the Qt tools. + +On Mac OS X: + +For the binary distribution, the qtdemo executable is installed in the +/Developer/Applications/Qt directory. For the source distribution, it is +installed alongside the other Qt tools on the path specified when Qt is +configured. + +On Unix/Linux: + +The qtdemo executable is installed alongside the other Qt tools on the path +specified when Qt is configured. + +On all platforms: + +The source code for the launcher can be found in the demos/qtdemo directory +in the Qt package. This example is built at the same time as the Qt libraries, +tools, examples, and demonstrations. diff --git a/examples/assistant/assistant.pro b/examples/assistant/assistant.pro new file mode 100644 index 0000000000..14771788e0 --- /dev/null +++ b/examples/assistant/assistant.pro @@ -0,0 +1,8 @@ +TEMPLATE = subdirs +SUBDIRS = simpletextviewer + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/assistant +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS assistant.pro README +sources.path = $$[QT_INSTALL_EXAMPLES]/assistant +INSTALLS += target sources diff --git a/examples/assistant/simpletextviewer/documentation/about.txt b/examples/assistant/simpletextviewer/documentation/about.txt new file mode 100644 index 0000000000..eeab35f4a6 --- /dev/null +++ b/examples/assistant/simpletextviewer/documentation/about.txt @@ -0,0 +1,9 @@ +The Simple Text Viewer enables the user to select and view existing +files. + +HTML files is displayed using rich text, while other files are +presented as plain text. The application provides a file dialog +allowing the user to search for files using wildcard matching. The +search is performed within in the specified directory, and the user is +given an option to browse the existing file system to find the +relevant directory. diff --git a/examples/assistant/simpletextviewer/documentation/browse.html b/examples/assistant/simpletextviewer/documentation/browse.html new file mode 100644 index 0000000000..987abf31f6 --- /dev/null +++ b/examples/assistant/simpletextviewer/documentation/browse.html @@ -0,0 +1,34 @@ + + + + Browse + + + +

Browse

+ +

+ The file dialog let you browse the current file system to + specify the directory in which the file you want to open + resides. + Note that only the specified directory will be searched, any + subdirectories will simply be ignored. +

+ +
+
+ + + + +
+ +
+
+

+ See also: File Dialog, Wildcard Matching, + Find File +

+ + + diff --git a/examples/assistant/simpletextviewer/documentation/filedialog.html b/examples/assistant/simpletextviewer/documentation/filedialog.html new file mode 100644 index 0000000000..afa65ed577 --- /dev/null +++ b/examples/assistant/simpletextviewer/documentation/filedialog.html @@ -0,0 +1,48 @@ + + + + File Dialog + + + +

File Dialog

+ +

+ In the file dialog you can name a particular file name, or + search for files using wildcard matching, i.e. specify a + file name containing wildcards. In addition you must specify + the directory in which the file you search for resides. +

+ +
+
+ + + + +
+ +
+
+

+ By default the dialog will search for all files (*) in the + current directory (the directory the application is run from). +

+ +

+ When editing the file name and directory parameters, an + overview of the matching files are displayed in the + dialog. The overview is updated whenever the parameters + change. +

+ +
+
+

+ See also: Browse, Wildcard Matching, + Find File +

+ + + + diff --git a/examples/assistant/simpletextviewer/documentation/findfile.html b/examples/assistant/simpletextviewer/documentation/findfile.html new file mode 100644 index 0000000000..32e0147181 --- /dev/null +++ b/examples/assistant/simpletextviewer/documentation/findfile.html @@ -0,0 +1,32 @@ + + + + Find File + + + +

Find File

+ +

+ To open and view a file in the Simple Text Viewer, select the + 'Open...' option in the 'File' menu. The application will then + provide you with a file dialog that you can use to search for + any existing file. +

+ +
+
+ + + + +
+ +
+
+

+ See also: Open File, File Dialog +

+ + + diff --git a/examples/assistant/simpletextviewer/documentation/images/browse.png b/examples/assistant/simpletextviewer/documentation/images/browse.png new file mode 100644 index 0000000000..86db6b19eb Binary files /dev/null and b/examples/assistant/simpletextviewer/documentation/images/browse.png differ diff --git a/examples/assistant/simpletextviewer/documentation/images/fadedfilemenu.png b/examples/assistant/simpletextviewer/documentation/images/fadedfilemenu.png new file mode 100644 index 0000000000..fde0e43f67 Binary files /dev/null and b/examples/assistant/simpletextviewer/documentation/images/fadedfilemenu.png differ diff --git a/examples/assistant/simpletextviewer/documentation/images/filedialog.png b/examples/assistant/simpletextviewer/documentation/images/filedialog.png new file mode 100644 index 0000000000..883a33a269 Binary files /dev/null and b/examples/assistant/simpletextviewer/documentation/images/filedialog.png differ diff --git a/examples/assistant/simpletextviewer/documentation/images/handbook.png b/examples/assistant/simpletextviewer/documentation/images/handbook.png new file mode 100644 index 0000000000..3bd2b928b0 Binary files /dev/null and b/examples/assistant/simpletextviewer/documentation/images/handbook.png differ diff --git a/examples/assistant/simpletextviewer/documentation/images/mainwindow.png b/examples/assistant/simpletextviewer/documentation/images/mainwindow.png new file mode 100644 index 0000000000..c28d5e9ffe Binary files /dev/null and b/examples/assistant/simpletextviewer/documentation/images/mainwindow.png differ diff --git a/examples/assistant/simpletextviewer/documentation/images/open.png b/examples/assistant/simpletextviewer/documentation/images/open.png new file mode 100644 index 0000000000..1e5bba3c8c Binary files /dev/null and b/examples/assistant/simpletextviewer/documentation/images/open.png differ diff --git a/examples/assistant/simpletextviewer/documentation/images/wildcard.png b/examples/assistant/simpletextviewer/documentation/images/wildcard.png new file mode 100644 index 0000000000..6e83a56cc4 Binary files /dev/null and b/examples/assistant/simpletextviewer/documentation/images/wildcard.png differ diff --git a/examples/assistant/simpletextviewer/documentation/index.html b/examples/assistant/simpletextviewer/documentation/index.html new file mode 100644 index 0000000000..5a7b1d5fac --- /dev/null +++ b/examples/assistant/simpletextviewer/documentation/index.html @@ -0,0 +1,41 @@ + + + + Manual + + + +

Simple Text Viewer

+ +

+ The Simple Text Viewer enables the user to select and view + existing files. +

+ +

+ +

+ +

+ HTML files is displayed using rich text, while + other files are presented as plain text. The application + provides a file dialog allowing the user to search for files + using wildcard matching. The search is performed within in the + specified directory, and the user is given an option to browse + the existing file system to find the relevant directory. +

+ + + + + + + diff --git a/examples/assistant/simpletextviewer/documentation/intro.html b/examples/assistant/simpletextviewer/documentation/intro.html new file mode 100644 index 0000000000..2e2aa40de7 --- /dev/null +++ b/examples/assistant/simpletextviewer/documentation/intro.html @@ -0,0 +1,28 @@ + + + + Manual + + + +

Simple Text Viewer

+ +

+ The Simple Text Viewer enables the user to select and view + existing files. +

+ +

+ +

+ +

+ The application provides its own custom documentation that is + available through the Help menu in the main window's menubar + and through the Help button in the application's find file + dialog. +

+ + + + diff --git a/examples/assistant/simpletextviewer/documentation/openfile.html b/examples/assistant/simpletextviewer/documentation/openfile.html new file mode 100644 index 0000000000..e172de95ea --- /dev/null +++ b/examples/assistant/simpletextviewer/documentation/openfile.html @@ -0,0 +1,36 @@ + + + + Open File + + + +

Open File

+ +

+ Once the file you want to view appears in the dialog's + display, you can open it in two different ways. +

+ +

+ By pressing the 'Open' button the currently selected file will + be opened. By default, the first file in the list of matching + files is selected. Another way of opening a file is to simply + double click the displayed file name. +

+ +
+
+ + + + +
+ +
+
+

+ See also: Find File +

+ + diff --git a/examples/assistant/simpletextviewer/documentation/simpletextviewer.adp b/examples/assistant/simpletextviewer/documentation/simpletextviewer.adp new file mode 100644 index 0000000000..660df4f382 --- /dev/null +++ b/examples/assistant/simpletextviewer/documentation/simpletextviewer.adp @@ -0,0 +1,40 @@ + + + + + + simpletextviewer + Simple Text Viewer + images/handbook.png + index.html + About Simple Text Viewer + about.txt + . + + + +
+ Display + Rich text + Plain text + Find + File menu + File name + File dialog + File globbing + Wildcard matching + Wildcard syntax + Browse + Directory + Open + Select + +
+
+
+
+
+ + + + diff --git a/examples/assistant/simpletextviewer/documentation/wildcardmatching.html b/examples/assistant/simpletextviewer/documentation/wildcardmatching.html new file mode 100644 index 0000000000..eb1839a068 --- /dev/null +++ b/examples/assistant/simpletextviewer/documentation/wildcardmatching.html @@ -0,0 +1,57 @@ + + + + Wildcard Matching + + + +

Wildcard Matching

+ +

+ Most command shells such as bash or cmd.exe support "file + globbing", the ability to identify a group of files by using + wildcards. + +
+
+ + + + +
+ +
+
+

+ Wildcard matching provides four features: +

+ +
    +
  • Any character represents itself apart from those + mentioned below. Thus 'c' matches the character 'c'. +
  • +
  • The '?' character matches any single character.
  • +
  • The '*' matches zero or more of any characters.
  • +
  • Sets of characters can be represented in square brackets. + Within the character class, like outside, backslash + has no special meaning. +
  • +
+ +

+ For example we could identify HTML files with + *.html. This will match zero or more characters + followed by a dot followed by 'h', 't', 'm' and 'l'. +

+ +
+
+

+ See also: Browse, File Dialog, + Find File +

+ + + + + diff --git a/examples/assistant/simpletextviewer/findfiledialog.cpp b/examples/assistant/simpletextviewer/findfiledialog.cpp new file mode 100644 index 0000000000..f73657e0d4 --- /dev/null +++ b/examples/assistant/simpletextviewer/findfiledialog.cpp @@ -0,0 +1,221 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "findfiledialog.h" + +//! [0] +FindFileDialog::FindFileDialog(QTextEdit *editor, QAssistantClient *assistant, + QWidget *parent) + : QDialog(parent) +{ + currentAssistantClient = assistant; + currentEditor = editor; +//! [0] + + createButtons(); + createComboBoxes(); + createFilesTree(); + createLabels(); + createLayout(); + + directoryComboBox->addItem(QDir::toNativeSeparators(QDir::currentPath())); + fileNameComboBox->addItem("*"); + findFiles(); + + setWindowTitle(tr("Find File")); +//! [1] +} +//! [1] + +void FindFileDialog::browse() +{ + QString currentDirectory = directoryComboBox->currentText(); + QString newDirectory = QFileDialog::getExistingDirectory(this, + tr("Select Directory"), currentDirectory); + if (!newDirectory.isEmpty()) { + directoryComboBox->addItem(QDir::toNativeSeparators(newDirectory)); + directoryComboBox->setCurrentIndex(directoryComboBox->count() - 1); + update(); + } +} + +//! [2] +void FindFileDialog::help() +{ + currentAssistantClient->showPage(QLibraryInfo::location(QLibraryInfo::ExamplesPath) + + QDir::separator() + "assistant/simpletextviewer/documentation/filedialog.html"); +} +//! [2] + +void FindFileDialog::openFile(QTreeWidgetItem *item) +{ + if (!item) { + item = foundFilesTree->currentItem(); + if (!item) + return; + } + + QString fileName = item->text(0); + QString path = directoryComboBox->currentText() + QDir::separator(); + + QFile file(path + fileName); + if (file.open(QIODevice::ReadOnly)) { + QString data(file.readAll()); + + if (fileName.endsWith(".html")) + currentEditor->setHtml(data); + else + currentEditor->setPlainText(data); + } + close(); +} + +void FindFileDialog::update() +{ + findFiles(); + buttonBox->button(QDialogButtonBox::Open)->setEnabled( + foundFilesTree->topLevelItemCount() > 0); +} + +void FindFileDialog::findFiles() +{ + QRegExp filePattern(fileNameComboBox->currentText() + "*"); + filePattern.setPatternSyntax(QRegExp::Wildcard); + + QDir directory(directoryComboBox->currentText()); + + QStringList allFiles = directory.entryList(QDir::Files | QDir::NoSymLinks); + QStringList matchingFiles; + + foreach (QString file, allFiles) { + if (filePattern.exactMatch(file)) + matchingFiles << file; + } + showFiles(matchingFiles); +} + +void FindFileDialog::showFiles(const QStringList &files) +{ + foundFilesTree->clear(); + + for (int i = 0; i < files.count(); ++i) { + QTreeWidgetItem *item = new QTreeWidgetItem(foundFilesTree); + item->setText(0, files[i]); + } + + if (files.count() > 0) + foundFilesTree->setCurrentItem(foundFilesTree->topLevelItem(0)); +} + +void FindFileDialog::createButtons() +{ + browseButton = new QToolButton; + browseButton->setText(tr("...")); + connect(browseButton, SIGNAL(clicked()), this, SLOT(browse())); + + buttonBox = new QDialogButtonBox(QDialogButtonBox::Open + | QDialogButtonBox::Cancel + | QDialogButtonBox::Help); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(openFile())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(buttonBox, SIGNAL(helpRequested()), this, SLOT(help())); +} + +void FindFileDialog::createComboBoxes() +{ + directoryComboBox = new QComboBox; + fileNameComboBox = new QComboBox; + + fileNameComboBox->setEditable(true); + fileNameComboBox->setSizePolicy(QSizePolicy::Expanding, + QSizePolicy::Preferred); + + directoryComboBox->setMinimumContentsLength(30); + directoryComboBox->setSizeAdjustPolicy( + QComboBox::AdjustToMinimumContentsLength); + directoryComboBox->setSizePolicy(QSizePolicy::Expanding, + QSizePolicy::Preferred); + + connect(fileNameComboBox, SIGNAL(editTextChanged(const QString &)), + this, SLOT(update())); + connect(directoryComboBox, SIGNAL(currentIndexChanged(const QString &)), + this, SLOT(update())); +} + +void FindFileDialog::createFilesTree() +{ + foundFilesTree = new QTreeWidget; + foundFilesTree->setColumnCount(1); + foundFilesTree->setHeaderLabels(QStringList(tr("Matching Files"))); + foundFilesTree->setRootIsDecorated(false); + foundFilesTree->setSelectionMode(QAbstractItemView::SingleSelection); + + connect(foundFilesTree, SIGNAL(itemActivated(QTreeWidgetItem *, int)), + this, SLOT(openFile(QTreeWidgetItem *))); +} + +void FindFileDialog::createLabels() +{ + directoryLabel = new QLabel(tr("Search in:")); + fileNameLabel = new QLabel(tr("File name (including wildcards):")); +} + +void FindFileDialog::createLayout() +{ + QHBoxLayout *fileLayout = new QHBoxLayout; + fileLayout->addWidget(fileNameLabel); + fileLayout->addWidget(fileNameComboBox); + + QHBoxLayout *directoryLayout = new QHBoxLayout; + directoryLayout->addWidget(directoryLabel); + directoryLayout->addWidget(directoryComboBox); + directoryLayout->addWidget(browseButton); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(fileLayout); + mainLayout->addLayout(directoryLayout); + mainLayout->addWidget(foundFilesTree); + mainLayout->addStretch(); + mainLayout->addWidget(buttonBox); + setLayout(mainLayout); +} diff --git a/examples/assistant/simpletextviewer/findfiledialog.h b/examples/assistant/simpletextviewer/findfiledialog.h new file mode 100644 index 0000000000..0c89fda950 --- /dev/null +++ b/examples/assistant/simpletextviewer/findfiledialog.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FINDFILEDIALOG_H +#define FINDFILEDIALOG_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QComboBox; +class QDialogButtonBox; +class QLabel; +class QTextEdit; +class QToolButton; +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +//! [0] +class FindFileDialog : public QDialog +{ + Q_OBJECT + +public: + FindFileDialog(QTextEdit *editor, QAssistantClient *assistant, + QWidget *parent = 0); + +private slots: + void browse(); + void help(); + void openFile(QTreeWidgetItem *item = 0); + void update(); + +private: + void findFiles(); + void showFiles(const QStringList &files); + + void createButtons(); + void createComboBoxes(); + void createFilesTree(); + void createLabels(); + void createLayout(); + + QAssistantClient *currentAssistantClient; + QTextEdit *currentEditor; + QTreeWidget *foundFilesTree; + + QComboBox *directoryComboBox; + QComboBox *fileNameComboBox; + + QLabel *directoryLabel; + QLabel *fileNameLabel; + + QDialogButtonBox *buttonBox; + + QToolButton *browseButton; +}; +//! [0] + +#endif diff --git a/examples/assistant/simpletextviewer/main.cpp b/examples/assistant/simpletextviewer/main.cpp new file mode 100644 index 0000000000..1d51376c06 --- /dev/null +++ b/examples/assistant/simpletextviewer/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow window; + window.show(); + return app.exec(); +} diff --git a/examples/assistant/simpletextviewer/mainwindow.cpp b/examples/assistant/simpletextviewer/mainwindow.cpp new file mode 100644 index 0000000000..cc2f3c0486 --- /dev/null +++ b/examples/assistant/simpletextviewer/mainwindow.cpp @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "findfiledialog.h" + +//! [0] +MainWindow::MainWindow() +{ + textViewer = new QTextEdit; + textViewer->setReadOnly(true); + QFile file("documentation/intro.html"); + if (file.open(QIODevice::ReadOnly)) + textViewer->setHtml(file.readAll()); + + setCentralWidget(textViewer); + + createActions(); + createMenus(); + + initializeAssistant(); + + setWindowTitle(tr("Simple Text Viewer")); + resize(750, 400); +} +//! [0] + +//! [1] +void MainWindow::closeEvent(QCloseEvent *) +{ + if (assistantClient) + assistantClient->closeAssistant(); +} +//! [1] + +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.")); +} + +//! [2] +void MainWindow::assistant() +{ + assistantClient->showPage(QLibraryInfo::location(QLibraryInfo::ExamplesPath) + + QDir::separator() + + "assistant/simpletextviewer/documentation/index.html"); +} +//! [2] + +//! [3] +void MainWindow::open() +{ + FindFileDialog dialog(textViewer, assistantClient); + dialog.exec(); +} +//! [3] + +void MainWindow::createActions() +{ + assistantAct = new QAction(tr("Help Contents"), this); + assistantAct->setShortcut(tr("F1")); + connect(assistantAct, SIGNAL(triggered()), this, SLOT(assistant())); + + 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); +} + +//! [4] +void MainWindow::initializeAssistant() +{ + assistantClient = new QAssistantClient(QLibraryInfo::location(QLibraryInfo::BinariesPath), this); + + QStringList arguments; + arguments << "-profile" << QString("documentation") + QDir::separator() + QString("simpletextviewer.adp"); + assistantClient->setArguments(arguments); +} +//! [4] diff --git a/examples/assistant/simpletextviewer/mainwindow.h b/examples/assistant/simpletextviewer/mainwindow.h new file mode 100644 index 0000000000..b56d2017fa --- /dev/null +++ b/examples/assistant/simpletextviewer/mainwindow.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private slots: + void about(); +//! [0] + void assistant(); +//! [0] + void open(); + +protected: +//! [1] + void closeEvent(QCloseEvent *event); +//! [1] + +private: + void createActions(); + void createMenus(); +//! [2] + void initializeAssistant(); +//! [2] + +//! [3] + QAssistantClient *assistantClient; +//! [3] + QTextEdit *textViewer; + + QMenu *fileMenu; + QMenu *helpMenu; + + QAction *assistantAct; + QAction *clearAct; + QAction *openAct; + QAction *exitAct; + QAction *aboutAct; + QAction *aboutQtAct; +}; + +#endif diff --git a/examples/assistant/simpletextviewer/simpletextviewer.pro b/examples/assistant/simpletextviewer/simpletextviewer.pro new file mode 100644 index 0000000000..4b66edb3cc --- /dev/null +++ b/examples/assistant/simpletextviewer/simpletextviewer.pro @@ -0,0 +1,16 @@ +CONFIG += assistant + +QT += network + +HEADERS = mainwindow.h \ + findfiledialog.h +SOURCES = main.cpp \ + mainwindow.cpp \ + findfiledialog.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/assistant/simpletextviewer +sources.files = $$SOURCES $$HEADERS $$RESOURCES documentation *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/assistant/simpletextviewer +INSTALLS += target sources + -- cgit v1.2.3