Engauge Digitizer  2
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  paths << "/documentation/engauge.qhc";
48  paths << "/../share/doc/engauge-digitizer/engauge.qhc";
49 
50  QStringList::iterator itr;
51  for (itr = paths.begin(); itr != paths.end(); itr++) {
52 
53  QString pathAsIs = *itr;
54 
55  QFile fileAsIs (pathAsIs);
56  if (fileAsIs.exists()) {
57  return pathAsIs;
58  }
59 
60  QString pathWithPrefix = QApplication::applicationDirPath() + pathAsIs;
61 
62  QFile fileWithPrefix (pathWithPrefix);
63  if (fileWithPrefix.exists()) {
64  return pathWithPrefix;
65  }
66  }
67 
68  return ""; // Empty file, since help file was never found, will simply result in empty help contents
69 }
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