Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
HelpWindow.cpp
1 #include "HelpBrowser.h"
2 #include "HelpWindow.h"
3 #include "Logger.h"
4 #include <QApplication>
5 #include <QFile>
6 #include <QHelpContentWidget>
7 #include <QHelpEngine>
8 #include <QHelpIndexWidget>
9 #include <QSplitter>
10 #include <QTabWidget>
11 
12 const int MIN_WIDTH = 600;
13 const int MIN_HEIGHT = 600;
14 
15 HelpWindow::HelpWindow(QWidget *parent) :
16  QDockWidget (parent)
17 {
18  setMinimumWidth (MIN_WIDTH);
19  setMinimumHeight (MIN_HEIGHT);
20 
21  QHelpEngine *helpEngine = new QHelpEngine (helpPath());
22  helpEngine->setupData();
23 
24  QTabWidget *tabs = new QTabWidget;
25  tabs->addTab (helpEngine->contentWidget(),
26  "Contents");
27  tabs->addTab (helpEngine->indexWidget(),
28  "Index");
29 
30  HelpBrowser *browser = new HelpBrowser (helpEngine);
31  browser->setSource (QUrl ("qthelp://engaugedigitizer.net/doc/index.html"));
32  connect (helpEngine->contentWidget (), SIGNAL (linkActivated (QUrl)), browser, SLOT (setSource (QUrl)));
33  connect (helpEngine->indexWidget (), SIGNAL (linkActivated (QUrl, QString)), browser, SLOT (setSource (QUrl)));
34 
35  QSplitter *splitter = new QSplitter (Qt::Horizontal);
36  splitter->insertWidget (0, tabs);
37  splitter->insertWidget (1, browser);
38 
39  setWidget (splitter);
40 }
41 
42 QString HelpWindow::helpPath() const
43 {
44  // Possible locations of help file. Each entry is first tried as is, and then with
45  // applicationDirPath as a prefix. Each entry should probably start with a slash
46  QStringList paths;
47 #ifdef HELPDIR
48 #define QUOTE(string) _QUOTE(string)
49 #define _QUOTE(string) #string
50  QString path = QString ("%1/engauge.qhc")
51  .arg (QUOTE (HELPDIR));
52  paths << path;
53 #endif
54  paths << "/documentation/engauge.qhc";
55  paths << "/../share/doc/engauge-digitizer/engauge.qhc";
56 
57  QStringList::iterator itr;
58  for (itr = paths.begin(); itr != paths.end(); itr++) {
59 
60  QString pathAsIs = *itr;
61 
62  QFile fileAsIs (pathAsIs);
63  if (fileAsIs.exists()) {
64  return pathAsIs;
65  }
66 
67  QString pathWithPrefix = QApplication::applicationDirPath() + pathAsIs;
68 
69  QFile fileWithPrefix (pathWithPrefix);
70  if (fileWithPrefix.exists()) {
71  return pathWithPrefix;
72  }
73  }
74 
75  return ""; // Empty file, since help file was never found, will simply result in empty help contents
76 }
HelpWindow(QWidget *parent)
Single constructor.
Definition: HelpWindow.cpp:15
Text browser with resource loading enhanced for use as help text browser.
Definition: HelpBrowser.h:9