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  QHelpEngine *helpEngine = new QHelpEngine (helpPath());
29  helpEngine->setupData();
30 
31  QTabWidget *tabs = new QTabWidget;
32  tabs->addTab (helpEngine->contentWidget(),
33  tr ("Contents"));
34  tabs->addTab (helpEngine->indexWidget(),
35  tr ("Index"));
36 
37  HelpBrowser *browser = new HelpBrowser (helpEngine);
38 
39  // URL is constructed from <namespace>, <virtualFolder> and <file> in engauge.qhp
40  browser->setSource (QUrl ("qthelp://engaugedigitizer.net/doc/index.html"));
41 
42  connect (helpEngine->contentWidget (), SIGNAL (linkActivated (QUrl)), browser, SLOT (setSource (QUrl)));
43  connect (helpEngine->indexWidget (), SIGNAL (linkActivated (QUrl, QString)), browser, SLOT (setSource (QUrl)));
44 
45  QSplitter *splitter = new QSplitter (Qt::Horizontal);
46  splitter->insertWidget (0, tabs);
47  splitter->insertWidget (1, browser);
48 
49  setWidget (splitter);
50 }
51 
52 QString HelpWindow::helpPath() const
53 {
54  // Possible locations of help file. Each entry is first tried as is, and then with
55  // applicationDirPath as a prefix. Each entry should probably start with a slash
56 
57  QStringList paths;
58 #ifdef HELPDIR
59 #define QUOTE(string) _QUOTE(string)
60 #define _QUOTE(string) #string
61  QString path = QString ("%1/engauge.qhc")
62  .arg (QUOTE (HELPDIR));
63  paths << path;
64 #endif
65 #ifdef OSX
66  paths << "/../Resources/engauge.qhc";
67 #else
68  paths << "/documentation/engauge.qhc";
69  paths << "/../share/doc/engauge-digitizer/engauge.qhc";
70 #endif
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 
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