NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxHelpBrowser.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxHelpBrowser.h"
13 
14 #include <QHelpEngine>
15 #include "cxHelpEngine.h"
16 #include "cxTypeConversions.h"
17 #include <iostream>
18 #include <QDesktopServices>
19 
20 namespace cx
21 {
22 HelpBrowser::HelpBrowser(QWidget *parent, HelpEnginePtr engine)
23  : QTextBrowser(parent), mEngine(engine)
24 {
25 }
26 
27 void HelpBrowser::showHelpForKeyword(const QString &id)
28 {
29  if (mEngine->engine())
30  {
31  QMap<QString, QUrl> links = mEngine->engine()->linksForIdentifier(id);
32  if (links.count())
33  {
34  setSource(links.first());
35  }
36  }
37 }
38 
39 void HelpBrowser::setSource(const QUrl& name)
40 {
41  if (name.scheme() == "qthelp")
42  QTextBrowser::setSource(name);
43  else
44  {
45  QDesktopServices::openUrl(name);
46  }
47 
48 }
49 
51 {
52  connect(mEngine.get(), SIGNAL(keywordActivated(QString)), this, SLOT(showHelpForKeyword(const QString&)));
53 }
54 
55 QVariant HelpBrowser::loadResource(int type, const QUrl &name)
56 {
57  if (type < 4 && mEngine->engine())
58  {
59  QUrl url(name);
60  if (name.isRelative())
61  url = source().resolved(url);
62 
63  if (url.scheme() == "qthelp")
64  return QVariant(mEngine->engine()->fileData(url));
65  else
66  return QTextBrowser::loadResource(type, url);
67  }
68  return QVariant();
69 }
70 
71 }//end namespace cx
cx::HelpBrowser::setSource
virtual void setSource(const QUrl &name)
Definition: cxHelpBrowser.cpp:39
cx::HelpBrowser::listenToEngineKeywordActivated
void listenToEngineKeywordActivated()
Definition: cxHelpBrowser.cpp:50
cx::HelpBrowser::HelpBrowser
HelpBrowser(QWidget *parent, HelpEnginePtr engine)
Definition: cxHelpBrowser.cpp:22
cx::HelpEnginePtr
boost::shared_ptr< HelpEngine > HelpEnginePtr
Definition: cxHelpEngine.h:61
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxHelpEngine.h
cx::HelpBrowser::showHelpForKeyword
void showHelpForKeyword(const QString &id)
Definition: cxHelpBrowser.cpp:27
cxTypeConversions.h
cxHelpBrowser.h