Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
HelpWindow.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "HelpBrowser.h"
8 #include "HelpWindow.h"
9 #include "Logger.h"
10 #include <QApplication>
11 #include <QDir>
12 #include <QFileInfo>
13 #include <QHelpContentWidget>
14 #include <QHelpEngine>
15 #include <QHelpIndexWidget>
16 #include <QSplitter>
17 #include <QTabWidget>
18 
19 const int MIN_WIDTH = 600;
20 const int MIN_HEIGHT = 600;
21 
22 HelpWindow::HelpWindow(QWidget *parent) :
23  QDockWidget (parent)
24 {
25  setMinimumWidth (MIN_WIDTH);
26  setMinimumHeight (MIN_HEIGHT);
27 
28 #ifndef OSX_RELEASE
29  QHelpEngine *helpEngine = new QHelpEngine (helpPath());
30  helpEngine->setupData();
31 
32  QTabWidget *tabs = new QTabWidget;
33  tabs->addTab (helpEngine->contentWidget(),
34  tr ("Contents"));
35  tabs->addTab (helpEngine->indexWidget(),
36  tr ("Index"));
37 
38  HelpBrowser *browser = new HelpBrowser (helpEngine);
39 
40  // URL is constructed from <namespace>, <virtualFolder> and <file> in engauge.qhp. If this line shows
41  // the error message 'QTextBrowser: No document for qthelp...' then the qhc file has not been built
42  browser->setSource (QUrl ("qthelp://engaugedigitizer.net/doc/index.html"));
43 
44  connect (helpEngine->contentWidget (), SIGNAL (linkActivated (QUrl)), browser, SLOT (setSource (QUrl)));
45  connect (helpEngine->indexWidget (), SIGNAL (linkActivated (QUrl, QString)), browser, SLOT (setSource (QUrl)));
46 
47  QSplitter *splitter = new QSplitter (Qt::Horizontal);
48  splitter->insertWidget (0, tabs);
49  splitter->insertWidget (1, browser);
50 
51  setWidget (splitter);
52 #endif
53 }
54 
55 #ifndef OSX_RELEASE
56 QString HelpWindow::helpPath() const
57 {
58  // Possible locations of help file. Each entry is first tried as is, and then with
59  // applicationDirPath as a prefix. Each entry should probably start with a slash. This
60  // search approach offers some flexibility in the help file location
61  QStringList paths;
62 #ifdef HELPDIR
63 #define QUOTE(string) _QUOTE(string)
64 #define _QUOTE(string) #string
65  QString path = QString ("%1/engauge.qhc")
66  .arg (QUOTE (HELPDIR));
67  paths << path;
68 #endif
69  paths << "/documentation/engauge.qhc";
70  paths << "/../share/doc/engauge-digitizer/engauge.qhc";
71  paths << "/usr/share/engauge-digitizer-doc/engauge.qhc";
72 
73  QStringList::iterator itr;
74  for (itr = paths.begin(); itr != paths.end(); itr++) {
75 
76  QString pathAsIs = *itr;
77 
78  QFileInfo fileAsIs (pathAsIs);
79  if (fileAsIs.exists()) {
80  return pathAsIs;
81  }
82 
83  QString pathWithPrefix = QApplication::applicationDirPath() + pathAsIs;
84 
85  QFileInfo fileWithPrefix (pathWithPrefix);
86  if (fileWithPrefix.exists()) {
87  return pathWithPrefix;
88  }
89  }
90 
91  return ""; // Empty file, since help file was never found, will simply result in empty help contents
92 }
93 #endif
HelpWindow(QWidget *parent)
Single constructor.
Definition: HelpWindow.cpp:22
Text browser with resource loading enhanced for use as help text browser.
Definition: HelpBrowser.h:15