Fraxinus  18.10
An IGT application
cxHelpWidget.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 "cxHelpWidget.h"
13 
14 #include "boost/bind.hpp"
15 #include "boost/function.hpp"
16 #include <QHelpEngine>
17 #include <QSplitter>
18 #include <QHelpContentWidget>
19 #include <QHelpIndexWidget>
20 #include <QTabWidget>
21 
22 #include "cxTypeConversions.h"
23 #include "cxHelpEngine.h"
24 #include "cxHelpBrowser.h"
25 #include "cxHelpSearchWidget.h"
26 #include "cxHelpIndexWidget.h"
27 #include "cxSettings.h"
28 #include "cxLogger.h"
29 #include "cxDataLocations.h"
30 #include <QDesktopServices>
31 
32 namespace cx
33 {
34 
35 HelpWidget::HelpWidget(HelpEnginePtr engine, QWidget* parent) :
36  BaseWidget(parent, "help_widget", "Help"),
37  mVerticalLayout(NULL),
38  mTabWidget(NULL),
39  mEngine(engine)
40 {
41 }
42 
43 void HelpWidget::setup()
44 {
45  if (mVerticalLayout)
46  return;
47 
48 // this->setToolTip("Context-sensitive and browser help");
49  mVerticalLayout = new QVBoxLayout(this);
50  mVerticalLayout->setMargin(0);
51  mVerticalLayout->setSpacing(0);
52  this->setLayout(mVerticalLayout);
53  mTabWidget = new QTabWidget(this);
54  mTabWidget->setElideMode(Qt::ElideRight);
55 
56  QSplitter *splitter = new QSplitter(Qt::Horizontal);
57  mSplitter = splitter;
58 
59  HelpBrowser *browser = new HelpBrowser(this, mEngine);
61  connect(this, &HelpWidget::requestShowLink,
62  browser, &HelpBrowser::setSource);
63  mBrowser = browser;
64 
65  QHBoxLayout* buttonLayout = new QHBoxLayout;
66  // buttonLayout->setMargin(0);
67  mVerticalLayout->addLayout(buttonLayout);
68 
69  splitter->insertWidget(0, mTabWidget);
70  splitter->insertWidget(1, browser);
71  splitter->setStretchFactor(1, 1);
72  mVerticalLayout->addWidget(splitter);
73 
74  this->addContentWidget(mTabWidget, buttonLayout);
75  this->addSearchWidget(mTabWidget, buttonLayout);
76  this->addIndexWidget(mTabWidget, buttonLayout);
77 
78  this->addToggleTabWidgetButton(buttonLayout);
79  this->addWebNavigationButtons(buttonLayout);
80  this->addWebButton(buttonLayout);
81  buttonLayout->addStretch();
82 
83  browser->showHelpForKeyword("user_doc_overview");
84 
85  bool navVis = settings()->value("org.custusx.help/navigationVisible").toBool();
86  mTabWidget->setVisible(navVis);
87 }
88 
90 {}
91 
92 QSize HelpWidget::sizeHint() const
93 {
94  // Removing this gives a very small initial size.
95  // This also seems to be the widest possible.
96  return QSize(500,30);
97 }
98 
99 
100 void HelpWidget::addContentWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
101 {
102  QHelpContentWidget* contentWidget = mEngine->engine()->contentWidget();
103  tabWidget->addTab(contentWidget, "contents");
104 
105  boost::function<void()> f = boost::bind(&QHelpContentWidget::expandToDepth, contentWidget, 2);
106  connect(mEngine->engine()->contentModel(), &QHelpContentModel::contentsCreated, f);
107  contentWidget->expandToDepth(2); // in case contents have been created
108 
109  connect(mEngine->engine()->contentWidget(), &QHelpContentWidget::linkActivated,
111 }
112 
113 void HelpWidget::addWebNavigationButtons(QBoxLayout* buttonLayout)
114 {
115  QAction* back = this->createAction(this,
116  QIcon(":/icons/open_icon_library/arrow-left-3.png"),
117  "Back", "Back to previous page",
118  SLOT(backSlot()),
119  buttonLayout, new CXSmallToolButton());
120 
121  QAction* forward = this->createAction(this,
122  QIcon(":/icons/open_icon_library/arrow-right-3.png"),
123  "Forward", "Forward to next page",
124  SLOT(forwardSlot()),
125  buttonLayout, new CXSmallToolButton());
126 
127  connect(mBrowser, SIGNAL(backwardAvailable(bool)), back, SLOT(setEnabled(bool)));
128  connect(mBrowser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setEnabled(bool)));
129 }
130 
131 void HelpWidget::addWebButton(QBoxLayout* buttonLayout)
132 {
133  this->createAction2(this,
134  QIcon(":/icons/open_icon_library/applications-internet.png"),
135  "Web", "Open Web Documentation",
136  &HelpWidget::onGotoDocumentation,
137  buttonLayout, new CXSmallToolButton());
138 }
139 
140 void HelpWidget::onGotoDocumentation()
141 {
143  QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
144 }
145 
146 void HelpWidget::backSlot()
147 {
148  mBrowser->backward();
149 }
150 
151 void HelpWidget::forwardSlot()
152 {
153  mBrowser->forward();
154 }
155 
156 void HelpWidget::addToggleTabWidgetButton(QBoxLayout* buttonLayout)
157 {
158  QAction* action = this->createAction(this,
159  QIcon(":/icons/open_icon_library/view-list-tree.png"),
160  "Toggle show navigation controls", "",
161  SLOT(toggleShowNavigationControls()),
162  NULL);
163  action->setCheckable(true);
164  CXSmallToolButton* button = new CXSmallToolButton();
165  button->setDefaultAction(action);
166  buttonLayout->addWidget(button);
167  mShowNavigationControlsAction = action;
168 }
169 
170 void HelpWidget::addIndexWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
171 {
172  mIndexWidget = new HelpIndexWidget(mEngine, this);
173  tabWidget->addTab(mIndexWidget, "index");
174 
175  connect(mIndexWidget, &HelpIndexWidget::requestShowLink,
177 }
178 
179 void HelpWidget::addSearchWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
180 {
181  mSearchWidget = new HelpSearchWidget(mEngine, this);
182  tabWidget->addTab(mSearchWidget, "search");
183  connect(mSearchWidget, &HelpSearchWidget::requestShowLink,
185 }
186 
187 void HelpWidget::showEvent(QShowEvent* event)
188 {
189  QWidget::showEvent(event);
190  this->setModified();
191 }
192 
193 void HelpWidget::hideEvent(QHideEvent* event)
194 {
195  QWidget::hideEvent(event);
196 }
197 
198 void HelpWidget::prePaintEvent()
199 {
200  this->setup();
201 }
202 
203 void HelpWidget::toggleShowNavigationControls()
204 {
205  if (mTabWidget->isVisible())
206  mTabWidget->hide();
207  else
208  {
209  mTabWidget->show();
210 
211  QList<int> sizes = mSplitter->sizes();
212  if (sizes[0]==0)
213  {
214  sizes[0] = sizes[1]*1/3;
215  sizes[1] = sizes[1]*2/3;
216  mSplitter->setSizes(sizes);
217  }
218 
219  }
220  settings()->setValue("org.custusx.help/navigationVisible", mTabWidget->isVisible());
221 }
222 
223 }//end namespace cx
void requestShowLink(const QUrl &)
virtual ~HelpWidget()
void listenToEngineKeywordActivated()
static QString getWebsiteUserDocumentationURL()
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:129
void requestShowLink(const QUrl &)
HelpWidget(HelpEnginePtr engine, QWidget *parent=NULL)
void requestShowLink(const QUrl &)
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:58
void showHelpForKeyword(const QString &id)
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
virtual void setSource(const QUrl &name)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
virtual QSize sizeHint() const
boost::shared_ptr< HelpEngine > HelpEnginePtr
Definition: cxHelpEngine.h:61
Namespace for all CustusX production code.