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