Engauge Digitizer  2
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
41  browser->setSource (QUrl ("qthelp://engaugedigitizer.net/doc/index.html"));
42 
43  connect (helpEngine->contentWidget (), SIGNAL (linkActivated (QUrl)), browser, SLOT (setSource (QUrl)));
44  connect (helpEngine->indexWidget (), SIGNAL (linkActivated (QUrl, QString)), browser, SLOT (setSource (QUrl)));
45 
46  QSplitter *splitter = new QSplitter (Qt::Horizontal);
47  splitter->insertWidget (0, tabs);
48  splitter->insertWidget (1, browser);
49 
50  setWidget (splitter);
51 #endif
52 }
53 
54 #ifndef OSX_RELEASE
55 QString HelpWindow::helpPath() const
56 {
57  // Possible locations of help file. Each entry is first tried as is, and then with
58  // applicationDirPath as a prefix. Each entry should probably start with a slash. This
59  // search approach offers some flexibility in the help file location
60  QStringList paths;
61 #ifdef HELPDIR
62 #define QUOTE(string) _QUOTE(string)
63 #define _QUOTE(string) #string
64  QString path = QString ("%1/engauge.qhc")
65  .arg (QUOTE (HELPDIR));
66  paths << path;
67 #endif
68  paths << "/documentation/engauge.qhc";
69  paths << "/../share/doc/engauge-digitizer/engauge.qhc";
70  paths << "/usr/share/engauge-digitizer-doc/engauge.qhc";
71 
72  QStringList::iterator itr;
73  for (itr = paths.begin(); itr != paths.end(); itr++) {
74 
75  QString pathAsIs = *itr;
76 
77  QFileInfo fileAsIs (pathAsIs);
78  if (fileAsIs.exists()) {
79  return pathAsIs;
80  }
81 
82  QString pathWithPrefix = QApplication::applicationDirPath() + pathAsIs;
83 
84  QFileInfo fileWithPrefix (pathWithPrefix);
85  if (fileWithPrefix.exists()) {
86  return pathWithPrefix;
87  }
88  }
89 
90  return ""; // Empty file, since help file was never found, will simply result in empty help contents
91 }
92 #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