PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Qt/Widgets/pqHelpWindow.cxx

https://github.com/Kitware/ParaView
C++ | 168 lines | 105 code | 22 blank | 41 comment | 4 complexity | edff98793848d45fbc3b6c99c119c7ec MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. /*=========================================================================
  2. Program: ParaView
  3. Module: pqHelpWindow.cxx
  4. Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
  5. All rights reserved.
  6. ParaView is a free software; you can redistribute it and/or modify it
  7. under the terms of the ParaView license version 1.2.
  8. See License_v1.2.txt for the full ParaView license.
  9. A copy of this license can be obtained by contacting
  10. Kitware Inc.
  11. 28 Corporate Drive
  12. Clifton Park, NY 12065
  13. USA
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. ========================================================================*/
  26. #include "pqHelpWindow.h"
  27. #include "pqQtWidgetsConfig.h" // for PARAVIEW_USE_QTWEBENGINE
  28. #include "ui_pqHelpWindow.h"
  29. #include <cassert>
  30. #include <QDebug>
  31. #include <QDesktopServices>
  32. #include <QHelpContentWidget>
  33. #include <QHelpEngine>
  34. #include <QHelpIndexWidget>
  35. #include <QHelpSearchEngine>
  36. #include <QHelpSearchQueryWidget>
  37. #include <QHelpSearchResultWidget>
  38. #include <QPointer>
  39. #include <QUrl>
  40. class pqBrowser
  41. {
  42. public:
  43. pqBrowser() = default;
  44. virtual ~pqBrowser() = default;
  45. virtual QWidget* widget() const = 0;
  46. virtual void setUrl(const QUrl& url) = 0;
  47. private:
  48. Q_DISABLE_COPY(pqBrowser)
  49. };
  50. template <class T>
  51. class pqBrowserTemplate : public pqBrowser
  52. {
  53. QPointer<T> Widget;
  54. public:
  55. pqBrowserTemplate(QHelpEngine* engine, pqHelpWindow* self)
  56. {
  57. this->Widget = T::newInstance(engine, self);
  58. }
  59. ~pqBrowserTemplate() override { delete this->Widget; }
  60. QWidget* widget() const override { return this->Widget; }
  61. void setUrl(const QUrl& url) override { this->Widget->setUrl(url); }
  62. };
  63. #if PARAVIEW_USE_QTWEBENGINE
  64. #include "pqHelpWindowWebEngine.h"
  65. typedef pqBrowserTemplate<pqWebView> PQBROWSER_TYPE;
  66. #else
  67. #include "pqHelpWindowNoWebEngine.h"
  68. typedef pqBrowserTemplate<pqTextBrowser> PQBROWSER_TYPE;
  69. #endif
  70. // ****************************************************************************
  71. // CLASS pqHelpWindow
  72. // ****************************************************************************
  73. //-----------------------------------------------------------------------------
  74. pqHelpWindow::pqHelpWindow(QHelpEngine* engine, QWidget* parentObject, Qt::WindowFlags parentFlags)
  75. : Superclass(parentObject, parentFlags)
  76. , HelpEngine(engine)
  77. , Browser(new PQBROWSER_TYPE(this->HelpEngine, this))
  78. {
  79. assert(engine != nullptr);
  80. Ui::pqHelpWindow ui;
  81. ui.setupUi(this);
  82. QObject::connect(
  83. this->HelpEngine, SIGNAL(warning(const QString&)), this, SIGNAL(helpWarnings(const QString&)));
  84. this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
  85. this->tabifyDockWidget(ui.contentsDock, ui.searchDock);
  86. ui.contentsDock->setWidget(this->HelpEngine->contentWidget());
  87. ui.contentsDock->raise();
  88. QWidget* searchPane = new QWidget(this);
  89. QVBoxLayout* vbox = new QVBoxLayout();
  90. searchPane->setLayout(vbox);
  91. vbox->addWidget(engine->searchEngine()->queryWidget());
  92. vbox->addWidget(engine->searchEngine()->resultWidget());
  93. ui.searchDock->setWidget(searchPane);
  94. QObject::connect(engine->searchEngine()->queryWidget(), SIGNAL(search()), this, SLOT(search()));
  95. QObject::connect(engine->searchEngine()->resultWidget(), SIGNAL(requestShowLink(const QUrl&)),
  96. this, SLOT(showPage(const QUrl&)));
  97. this->setCentralWidget(this->Browser->widget());
  98. QObject::connect(this->HelpEngine->contentWidget(), SIGNAL(linkActivated(const QUrl&)), this,
  99. SLOT(showPage(const QUrl&)));
  100. }
  101. //-----------------------------------------------------------------------------
  102. pqHelpWindow::~pqHelpWindow() = default;
  103. //-----------------------------------------------------------------------------
  104. void pqHelpWindow::showPage(const QString& url)
  105. {
  106. this->showPage(QUrl(url));
  107. }
  108. //-----------------------------------------------------------------------------
  109. void pqHelpWindow::showPage(const QUrl& url)
  110. {
  111. if (url.scheme() == "http")
  112. {
  113. QDesktopServices::openUrl(url);
  114. }
  115. else
  116. {
  117. this->Browser->setUrl(url);
  118. }
  119. }
  120. //-----------------------------------------------------------------------------
  121. void pqHelpWindow::search()
  122. {
  123. QString query = this->HelpEngine->searchEngine()->queryWidget()->searchInput();
  124. this->HelpEngine->searchEngine()->search(query);
  125. }
  126. //-----------------------------------------------------------------------------
  127. void pqHelpWindow::showHomePage(const QString& namespace_name)
  128. {
  129. QList<QUrl> html_pages = this->HelpEngine->files(namespace_name, QStringList(), "html");
  130. // now try to locate a file named index.html in this collection.
  131. Q_FOREACH (QUrl url, html_pages)
  132. {
  133. if (url.path().endsWith("index.html"))
  134. {
  135. this->showPage(url);
  136. return;
  137. }
  138. }
  139. qWarning() << "Could not locate index.html";
  140. }