Fraxinus  17.12
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxHelpWidget.h"
34 
35 #include "boost/bind.hpp"
36 #include "boost/function.hpp"
37 #include <QHelpEngine>
38 #include <QSplitter>
39 #include <QHelpContentWidget>
40 #include <QHelpIndexWidget>
41 #include <QTabWidget>
42 
43 #include "cxTypeConversions.h"
44 #include "cxHelpEngine.h"
45 #include "cxHelpBrowser.h"
46 #include "cxHelpSearchWidget.h"
47 #include "cxHelpIndexWidget.h"
48 #include "cxSettings.h"
49 #include "cxLogger.h"
50 #include "cxDataLocations.h"
51 #include <QDesktopServices>
52 
53 namespace cx
54 {
55 
56 HelpWidget::HelpWidget(HelpEnginePtr engine, QWidget* parent) :
57  BaseWidget(parent, "help_widget", "Help"),
58  mVerticalLayout(NULL),
59  mTabWidget(NULL),
60  mEngine(engine)
61 {
62 }
63 
64 void HelpWidget::setup()
65 {
66  if (mVerticalLayout)
67  return;
68 
69 // this->setToolTip("Context-sensitive and browser help");
70  mVerticalLayout = new QVBoxLayout(this);
71  mVerticalLayout->setMargin(0);
72  mVerticalLayout->setSpacing(0);
73  this->setLayout(mVerticalLayout);
74  mTabWidget = new QTabWidget(this);
75  mTabWidget->setElideMode(Qt::ElideRight);
76 
77  QSplitter *splitter = new QSplitter(Qt::Horizontal);
78  mSplitter = splitter;
79 
80  HelpBrowser *browser = new HelpBrowser(this, mEngine);
82  connect(this, &HelpWidget::requestShowLink,
83  browser, &HelpBrowser::setSource);
84  mBrowser = browser;
85 
86  QHBoxLayout* buttonLayout = new QHBoxLayout;
87  // buttonLayout->setMargin(0);
88  mVerticalLayout->addLayout(buttonLayout);
89 
90  splitter->insertWidget(0, mTabWidget);
91  splitter->insertWidget(1, browser);
92  splitter->setStretchFactor(1, 1);
93  mVerticalLayout->addWidget(splitter);
94 
95  this->addContentWidget(mTabWidget, buttonLayout);
96  this->addSearchWidget(mTabWidget, buttonLayout);
97  this->addIndexWidget(mTabWidget, buttonLayout);
98 
99  this->addToggleTabWidgetButton(buttonLayout);
100  this->addWebNavigationButtons(buttonLayout);
101  this->addWebButton(buttonLayout);
102  buttonLayout->addStretch();
103 
104  browser->showHelpForKeyword("user_doc_overview");
105 
106  bool navVis = settings()->value("org.custusx.help/navigationVisible").toBool();
107  mTabWidget->setVisible(navVis);
108 }
109 
111 {}
112 
113 QSize HelpWidget::sizeHint() const
114 {
115  // Removing this gives a very small initial size.
116  // This also seems to be the widest possible.
117  return QSize(500,30);
118 }
119 
120 
121 void HelpWidget::addContentWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
122 {
123  QHelpContentWidget* contentWidget = mEngine->engine()->contentWidget();
124  tabWidget->addTab(contentWidget, "contents");
125 
126  boost::function<void()> f = boost::bind(&QHelpContentWidget::expandToDepth, contentWidget, 2);
127  connect(mEngine->engine()->contentModel(), &QHelpContentModel::contentsCreated, f);
128  contentWidget->expandToDepth(2); // in case contents have been created
129 
130  connect(mEngine->engine()->contentWidget(), &QHelpContentWidget::linkActivated,
132 }
133 
134 void HelpWidget::addWebNavigationButtons(QBoxLayout* buttonLayout)
135 {
136  QAction* back = this->createAction(this,
137  QIcon(":/icons/open_icon_library/arrow-left-3.png"),
138  "Back", "Back to previous page",
139  SLOT(backSlot()),
140  buttonLayout, new CXSmallToolButton());
141 
142  QAction* forward = this->createAction(this,
143  QIcon(":/icons/open_icon_library/arrow-right-3.png"),
144  "Forward", "Forward to next page",
145  SLOT(forwardSlot()),
146  buttonLayout, new CXSmallToolButton());
147 
148  connect(mBrowser, SIGNAL(backwardAvailable(bool)), back, SLOT(setEnabled(bool)));
149  connect(mBrowser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setEnabled(bool)));
150 }
151 
152 void HelpWidget::addWebButton(QBoxLayout* buttonLayout)
153 {
154  this->createAction2(this,
155  QIcon(":/icons/open_icon_library/applications-internet.png"),
156  "Web", "Open Web Documentation",
157  &HelpWidget::onGotoDocumentation,
158  buttonLayout, new CXSmallToolButton());
159 }
160 
161 void HelpWidget::onGotoDocumentation()
162 {
164  QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
165 }
166 
167 void HelpWidget::backSlot()
168 {
169  mBrowser->backward();
170 }
171 
172 void HelpWidget::forwardSlot()
173 {
174  mBrowser->forward();
175 }
176 
177 void HelpWidget::addToggleTabWidgetButton(QBoxLayout* buttonLayout)
178 {
179  QAction* action = this->createAction(this,
180  QIcon(":/icons/open_icon_library/view-list-tree.png"),
181  "Toggle show navigation controls", "",
182  SLOT(toggleShowNavigationControls()),
183  NULL);
184  action->setCheckable(true);
185  CXSmallToolButton* button = new CXSmallToolButton();
186  button->setDefaultAction(action);
187  buttonLayout->addWidget(button);
188  mShowNavigationControlsAction = action;
189 }
190 
191 void HelpWidget::addIndexWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
192 {
193  mIndexWidget = new HelpIndexWidget(mEngine, this);
194  tabWidget->addTab(mIndexWidget, "index");
195 
196  connect(mIndexWidget, &HelpIndexWidget::requestShowLink,
198 }
199 
200 void HelpWidget::addSearchWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
201 {
202  mSearchWidget = new HelpSearchWidget(mEngine, this);
203  tabWidget->addTab(mSearchWidget, "search");
204  connect(mSearchWidget, &HelpSearchWidget::requestShowLink,
206 }
207 
208 void HelpWidget::showEvent(QShowEvent* event)
209 {
210  QWidget::showEvent(event);
211  this->setModified();
212 }
213 
214 void HelpWidget::hideEvent(QHideEvent* event)
215 {
216  QWidget::hideEvent(event);
217 }
218 
219 void HelpWidget::prePaintEvent()
220 {
221  this->setup();
222 }
223 
224 void HelpWidget::toggleShowNavigationControls()
225 {
226  if (mTabWidget->isVisible())
227  mTabWidget->hide();
228  else
229  {
230  mTabWidget->show();
231 
232  QList<int> sizes = mSplitter->sizes();
233  if (sizes[0]==0)
234  {
235  sizes[0] = sizes[1]*1/3;
236  sizes[1] = sizes[1]*2/3;
237  mSplitter->setSizes(sizes);
238  }
239 
240  }
241  settings()->setValue("org.custusx.help/navigationVisible", mTabWidget->isVisible());
242 }
243 
244 }//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:87
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:150
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:79
void showHelpForKeyword(const QString &id)
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
virtual void setSource(const QUrl &name)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:109
virtual QSize sizeHint() const
boost::shared_ptr< HelpEngine > HelpEnginePtr
Definition: cxHelpEngine.h:82
Namespace for all CustusX production code.