diff options
Diffstat (limited to 'examples/assistant')
13 files changed, 588 insertions, 3 deletions
diff --git a/examples/assistant/assistant.pro b/examples/assistant/assistant.pro index fd289a670..578c7ff5b 100644 --- a/examples/assistant/assistant.pro +++ b/examples/assistant/assistant.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += simpletextviewer +SUBDIRS += simpletextviewer \ + remotecontrol diff --git a/examples/assistant/simpletextviewer/doc/images/simpletextviewer-example.png b/examples/assistant/doc/images/simpletextviewer-example.png Binary files differindex 95d290539..95d290539 100644 --- a/examples/assistant/simpletextviewer/doc/images/simpletextviewer-example.png +++ b/examples/assistant/doc/images/simpletextviewer-example.png diff --git a/examples/assistant/simpletextviewer/doc/images/simpletextviewer-findfiledialog.png b/examples/assistant/doc/images/simpletextviewer-findfiledialog.png Binary files differindex f6e55f099..f6e55f099 100644 --- a/examples/assistant/simpletextviewer/doc/images/simpletextviewer-findfiledialog.png +++ b/examples/assistant/doc/images/simpletextviewer-findfiledialog.png diff --git a/examples/assistant/simpletextviewer/doc/images/simpletextviewer-mainwindow.png b/examples/assistant/doc/images/simpletextviewer-mainwindow.png Binary files differindex 98c1c61cc..98c1c61cc 100644 --- a/examples/assistant/simpletextviewer/doc/images/simpletextviewer-mainwindow.png +++ b/examples/assistant/doc/images/simpletextviewer-mainwindow.png diff --git a/examples/assistant/doc/src/remotecontrol.qdoc b/examples/assistant/doc/src/remotecontrol.qdoc new file mode 100644 index 000000000..5a8106fdb --- /dev/null +++ b/examples/assistant/doc/src/remotecontrol.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example remotecontrol + \ingroup examples-qtassistant + \title Remote Control Example + + \brief Using and controlling Qt Assistant as a help viewer. +*/ diff --git a/examples/assistant/simpletextviewer/doc/src/simpletextviewer.qdoc b/examples/assistant/doc/src/simpletextviewer.qdoc index 5469e0270..bf74e10ed 100644 --- a/examples/assistant/simpletextviewer/doc/src/simpletextviewer.qdoc +++ b/examples/assistant/doc/src/simpletextviewer.qdoc @@ -27,10 +27,10 @@ /*! \example simpletextviewer + \ingroup examples-qtassistant \title Simple Text Viewer Example - \brief The Simple Text Viewer example shows how to use \QA as a customized - help viewer for your application. + \brief Using \QA as a customized help viewer for your application. \image simpletextviewer-example.png diff --git a/examples/assistant/remotecontrol/enter.png b/examples/assistant/remotecontrol/enter.png Binary files differnew file mode 100644 index 000000000..f397f4b9c --- /dev/null +++ b/examples/assistant/remotecontrol/enter.png diff --git a/examples/assistant/remotecontrol/main.cpp b/examples/assistant/remotecontrol/main.cpp new file mode 100644 index 000000000..a862cb2ad --- /dev/null +++ b/examples/assistant/remotecontrol/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWidgets/QApplication> +#include "remotecontrol.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(remotecontrol); + + QApplication a(argc, argv); + RemoteControl w; + w.show(); + a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); + return a.exec(); +} diff --git a/examples/assistant/remotecontrol/remotecontrol.cpp b/examples/assistant/remotecontrol/remotecontrol.cpp new file mode 100644 index 000000000..2569829a5 --- /dev/null +++ b/examples/assistant/remotecontrol/remotecontrol.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/QDir> +#include <QtCore/QProcess> +#include <QtCore/QTextStream> +#include <QtCore/QLibraryInfo> + +#include <QtWidgets/QMessageBox> + +#include "remotecontrol.h" + +RemoteControl::RemoteControl(QWidget *parent, Qt::WindowFlags flags) + : QMainWindow(parent, flags) +{ + ui.setupUi(this); + connect(ui.indexLineEdit, SIGNAL(returnPressed()), + this, SLOT(on_indexButton_clicked())); + connect(ui.identifierLineEdit, SIGNAL(returnPressed()), + this, SLOT(on_identifierButton_clicked())); + connect(ui.urlLineEdit, SIGNAL(returnPressed()), + this, SLOT(on_urlButton_clicked())); + + QString rc; + QTextStream(&rc) << QLatin1String("qthelp://com.trolltech.qt.") + << (QT_VERSION >> 16) << ((QT_VERSION >> 8) & 0xFF) + << (QT_VERSION & 0xFF) + << QLatin1String("/qdoc/index.html"); + + ui.startUrlLineEdit->setText(rc); + + process = new QProcess(this); + connect(process, SIGNAL(finished(int,QProcess::ExitStatus)), + this, SLOT(helpViewerClosed())); +} + +RemoteControl::~RemoteControl() +{ + if (process->state() == QProcess::Running) { + process->terminate(); + process->waitForFinished(3000); + } +} + +void RemoteControl::on_actionQuit_triggered() +{ + close(); +} + +void RemoteControl::on_launchButton_clicked() +{ + if (process->state() == QProcess::Running) + return; + + QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator(); +#if !defined(Q_OS_MAC) + app += QLatin1String("assistant"); +#else + app += QLatin1String("Assistant.app/Contents/MacOS/Assistant"); +#endif + + ui.contentsCheckBox->setChecked(true); + ui.indexCheckBox->setChecked(true); + ui.bookmarksCheckBox->setChecked(true); + + QStringList args; + args << QLatin1String("-enableRemoteControl"); + process->start(app, args); + if (!process->waitForStarted()) { + QMessageBox::critical(this, tr("Remote Control"), + tr("Could not start Qt Assistant from %1.").arg(app)); + return; + } + + if (!ui.startUrlLineEdit->text().isEmpty()) + sendCommand(QLatin1String("SetSource ") + + ui.startUrlLineEdit->text()); + + ui.launchButton->setEnabled(false); + ui.startUrlLineEdit->setEnabled(false); + ui.actionGroupBox->setEnabled(true); +} + +void RemoteControl::sendCommand(const QString &cmd) +{ + if (process->state() != QProcess::Running) + return; + process->write(cmd.toLocal8Bit() + '\n'); +} + +void RemoteControl::on_indexButton_clicked() +{ + sendCommand(QLatin1String("ActivateKeyword ") + + ui.indexLineEdit->text()); +} + +void RemoteControl::on_identifierButton_clicked() +{ + sendCommand(QLatin1String("ActivateIdentifier ") + + ui.identifierLineEdit->text()); +} + +void RemoteControl::on_urlButton_clicked() +{ + sendCommand(QLatin1String("SetSource ") + + ui.urlLineEdit->text()); +} + +void RemoteControl::on_syncContentsButton_clicked() +{ + sendCommand(QLatin1String("SyncContents")); +} + +void RemoteControl::on_contentsCheckBox_toggled(bool checked) +{ + sendCommand(checked ? + QLatin1String("Show Contents") : QLatin1String("Hide Contents")); +} + +void RemoteControl::on_indexCheckBox_toggled(bool checked) +{ + sendCommand(checked ? + QLatin1String("Show Index") : QLatin1String("Hide Index")); +} + +void RemoteControl::on_bookmarksCheckBox_toggled(bool checked) +{ + sendCommand(checked ? + QLatin1String("Show Bookmarks") : QLatin1String("Hide Bookmarks")); +} + +void RemoteControl::helpViewerClosed() +{ + ui.launchButton->setEnabled(true); + ui.startUrlLineEdit->setEnabled(true); + ui.actionGroupBox->setEnabled(false); +} diff --git a/examples/assistant/remotecontrol/remotecontrol.h b/examples/assistant/remotecontrol/remotecontrol.h new file mode 100644 index 000000000..ecf50edcb --- /dev/null +++ b/examples/assistant/remotecontrol/remotecontrol.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef REMOTECONTROL_H +#define REMOTECONTROL_H + +#include <QtWidgets/QMainWindow> +#include "ui_remotecontrol.h" + +QT_BEGIN_NAMESPACE +class QProcess; +QT_END_NAMESPACE; + +class RemoteControl : public QMainWindow +{ + Q_OBJECT + +public: + RemoteControl(QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~RemoteControl(); + +private: + Ui::RemoteControlClass ui; + QProcess *process; + +private slots: + void on_launchButton_clicked(); + void on_actionQuit_triggered(); + void on_indexButton_clicked(); + void on_identifierButton_clicked(); + void on_urlButton_clicked(); + void on_syncContentsButton_clicked(); + void on_contentsCheckBox_toggled(bool checked); + void on_indexCheckBox_toggled(bool checked); + void on_bookmarksCheckBox_toggled(bool checked); + void helpViewerClosed(); + + void sendCommand(const QString &cmd); +}; + +#endif // REMOTECONTROL_H diff --git a/examples/assistant/remotecontrol/remotecontrol.pro b/examples/assistant/remotecontrol/remotecontrol.pro new file mode 100644 index 000000000..78ce822d8 --- /dev/null +++ b/examples/assistant/remotecontrol/remotecontrol.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +QT += widgets + +HEADERS += remotecontrol.h +SOURCES += main.cpp \ + remotecontrol.cpp +FORMS += remotecontrol.ui +RESOURCES += remotecontrol.qrc + +target.path = $$[QT_INSTALL_EXAMPLES]/help/remotecontrol +INSTALLS += target + diff --git a/examples/assistant/remotecontrol/remotecontrol.qrc b/examples/assistant/remotecontrol/remotecontrol.qrc new file mode 100644 index 000000000..9b4299d21 --- /dev/null +++ b/examples/assistant/remotecontrol/remotecontrol.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/remotecontrol" > + <file>enter.png</file> + </qresource> +</RCC> diff --git a/examples/assistant/remotecontrol/remotecontrol.ui b/examples/assistant/remotecontrol/remotecontrol.ui new file mode 100644 index 000000000..1cfc7f540 --- /dev/null +++ b/examples/assistant/remotecontrol/remotecontrol.ui @@ -0,0 +1,228 @@ +<ui version="4.0" > + <class>RemoteControlClass</class> + <widget class="QMainWindow" name="RemoteControlClass" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>344</width> + <height>364</height> + </rect> + </property> + <property name="windowTitle" > + <string>RemoteControl</string> + </property> + <widget class="QWidget" name="centralWidget" > + <layout class="QGridLayout" > + <item row="0" column="0" > + <widget class="QLabel" name="label" > + <property name="text" > + <string>Start URL:</string> + </property> + </widget> + </item> + <item row="0" column="1" colspan="2" > + <widget class="QLineEdit" name="startUrlLineEdit" /> + </item> + <item row="1" column="1" > + <widget class="QPushButton" name="launchButton" > + <property name="text" > + <string>Launch Qt HelpViewer</string> + </property> + </widget> + </item> + <item row="1" column="2" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>101</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="1" > + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" > + <size> + <width>113</width> + <height>16</height> + </size> + </property> + </spacer> + </item> + <item row="3" column="0" colspan="3" > + <widget class="QGroupBox" name="actionGroupBox" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="title" > + <string>Actions</string> + </property> + <layout class="QGridLayout" > + <item row="0" column="0" > + <widget class="QLabel" name="label_2" > + <property name="text" > + <string>Search in Index:</string> + </property> + </widget> + </item> + <item row="0" column="1" colspan="2" > + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>0</number> + </property> + <item> + <widget class="QLineEdit" name="indexLineEdit" /> + </item> + <item> + <widget class="QToolButton" name="indexButton" > + <property name="text" > + <string/> + </property> + <property name="icon" > + <iconset resource="remotecontrol.qrc" >:/remotecontrol/enter.png</iconset> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="label_4" > + <property name="text" > + <string>Identifier:</string> + </property> + </widget> + </item> + <item row="1" column="1" colspan="2" > + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>0</number> + </property> + <item> + <widget class="QLineEdit" name="identifierLineEdit" /> + </item> + <item> + <widget class="QToolButton" name="identifierButton" > + <property name="text" > + <string/> + </property> + <property name="icon" > + <iconset resource="remotecontrol.qrc" >:/remotecontrol/enter.png</iconset> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="0" > + <widget class="QLabel" name="label_3" > + <property name="text" > + <string>Show URL:</string> + </property> + </widget> + </item> + <item row="2" column="1" colspan="2" > + <layout class="QHBoxLayout" > + <property name="spacing" > + <number>0</number> + </property> + <item> + <widget class="QLineEdit" name="urlLineEdit" /> + </item> + <item> + <widget class="QToolButton" name="urlButton" > + <property name="text" > + <string/> + </property> + <property name="icon" > + <iconset resource="remotecontrol.qrc" >:/remotecontrol/enter.png</iconset> + </property> + </widget> + </item> + </layout> + </item> + <item row="3" column="1" > + <widget class="QPushButton" name="syncContentsButton" > + <property name="text" > + <string>Sync Contents</string> + </property> + </widget> + </item> + <item row="3" column="2" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>81</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="4" column="0" colspan="3" > + <widget class="QCheckBox" name="contentsCheckBox" > + <property name="text" > + <string>Show Contents</string> + </property> + </widget> + </item> + <item row="5" column="0" > + <widget class="QCheckBox" name="indexCheckBox" > + <property name="text" > + <string>Show Index</string> + </property> + </widget> + </item> + <item row="6" column="0" colspan="3" > + <widget class="QCheckBox" name="bookmarksCheckBox" > + <property name="text" > + <string>Show Bookmarks</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menuBar" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>344</width> + <height>21</height> + </rect> + </property> + <widget class="QMenu" name="menuFile" > + <property name="title" > + <string>File</string> + </property> + <addaction name="actionQuit" /> + </widget> + <addaction name="menuFile" /> + </widget> + <widget class="QStatusBar" name="statusBar" /> + <action name="actionQuit" > + <property name="text" > + <string>Quit</string> + </property> + </action> + </widget> + <layoutdefault spacing="6" margin="11" /> + <resources> + <include location="remotecontrol.qrc" /> + </resources> + <connections/> +</ui> |