CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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, "HelpWidget", "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);
81  connect(this, &HelpWidget::requestShowLink,
82  browser, &HelpBrowser::setSource);
83  mBrowser = browser;
84 
85  QHBoxLayout* buttonLayout = new QHBoxLayout;
86  // buttonLayout->setMargin(0);
87  mVerticalLayout->addLayout(buttonLayout);
88 
89  splitter->insertWidget(0, mTabWidget);
90  splitter->insertWidget(1, browser);
91  splitter->setStretchFactor(1, 1);
92  mVerticalLayout->addWidget(splitter);
93 
94  this->addContentWidget(mTabWidget, buttonLayout);
95  this->addSearchWidget(mTabWidget, buttonLayout);
96  this->addIndexWidget(mTabWidget, buttonLayout);
97 
98  this->addToggleTabWidgetButton(buttonLayout);
99  this->addWebNavigationButtons(buttonLayout);
100  this->addWebButton(buttonLayout);
101  buttonLayout->addStretch();
102 
103  browser->showHelpForKeyword("user_doc_overview");
104 
105  bool navVis = settings()->value("org.custusx.help/navigationVisible").toBool();
106  mTabWidget->setVisible(navVis);
107 }
108 
110 {}
111 
112 QSize HelpWidget::sizeHint() const
113 {
114  // removing this gives a very small initial size
115  return QSize(250,30);
116 }
117 
118 
119 void HelpWidget::addContentWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
120 {
121  QHelpContentWidget* contentWidget = mEngine->engine()->contentWidget();
122  tabWidget->addTab(contentWidget, "contents");
123 
124  boost::function<void()> f = boost::bind(&QHelpContentWidget::expandToDepth, contentWidget, 2);
125  connect(mEngine->engine()->contentModel(), &QHelpContentModel::contentsCreated, f);
126  contentWidget->expandToDepth(2); // in case contents have been created
127 
128  connect(mEngine->engine()->contentWidget(), &QHelpContentWidget::linkActivated,
130 }
131 
132 void HelpWidget::addWebNavigationButtons(QBoxLayout* buttonLayout)
133 {
134  QAction* back = this->createAction(this,
135  QIcon(":/icons/open_icon_library/arrow-left-3.png"),
136  "Back", "Back to previous page",
137  SLOT(backSlot()),
138  buttonLayout, new CXSmallToolButton());
139 
140  QAction* forward = this->createAction(this,
141  QIcon(":/icons/open_icon_library/arrow-right-3.png"),
142  "Forward", "Forward to next page",
143  SLOT(forwardSlot()),
144  buttonLayout, new CXSmallToolButton());
145 
146  connect(mBrowser, SIGNAL(backwardAvailable(bool)), back, SLOT(setEnabled(bool)));
147  connect(mBrowser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setEnabled(bool)));
148 }
149 
150 void HelpWidget::addWebButton(QBoxLayout* buttonLayout)
151 {
152  this->createAction2(this,
153  QIcon(":/icons/open_icon_library/applications-internet.png"),
154  "Web", "Open Web Documentation",
155  &HelpWidget::onGotoDocumentation,
156  buttonLayout, new CXSmallToolButton());
157 }
158 
159 void HelpWidget::onGotoDocumentation()
160 {
162  QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
163 }
164 
165 void HelpWidget::backSlot()
166 {
167  mBrowser->backward();
168 }
169 
170 void HelpWidget::forwardSlot()
171 {
172  mBrowser->forward();
173 }
174 
175 void HelpWidget::addToggleTabWidgetButton(QBoxLayout* buttonLayout)
176 {
177  QAction* action = this->createAction(this,
178  QIcon(":/icons/open_icon_library/view-list-tree.png"),
179  "Toggle show navigation controls", "",
180  SLOT(toggleShowNavigationControls()),
181  NULL);
182  action->setCheckable(true);
183  CXSmallToolButton* button = new CXSmallToolButton();
184  button->setDefaultAction(action);
185  buttonLayout->addWidget(button);
186  mShowNavigationControlsAction = action;
187 }
188 
189 void HelpWidget::addIndexWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
190 {
191  mIndexWidget = new HelpIndexWidget(mEngine, this);
192  tabWidget->addTab(mIndexWidget, "index");
193 
194  connect(mIndexWidget, &HelpIndexWidget::requestShowLink,
196 }
197 
198 void HelpWidget::addSearchWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
199 {
200  mSearchWidget = new HelpSearchWidget(mEngine, this);
201  tabWidget->addTab(mSearchWidget, "search");
202  connect(mSearchWidget, &HelpSearchWidget::requestShowLink,
204 }
205 
206 void HelpWidget::showEvent(QShowEvent* event)
207 {
208  QWidget::showEvent(event);
209  this->setModified();
210 }
211 
212 void HelpWidget::hideEvent(QHideEvent* event)
213 {
214  QWidget::hideEvent(event);
215 }
216 
217 void HelpWidget::prePaintEvent()
218 {
219  this->setup();
220 }
221 
222 void HelpWidget::toggleShowNavigationControls()
223 {
224  if (mTabWidget->isVisible())
225  mTabWidget->hide();
226  else
227  {
228  mTabWidget->show();
229 
230  QList<int> sizes = mSplitter->sizes();
231  if (sizes[0]==0)
232  {
233  sizes[0] = sizes[1]*1/3;
234  sizes[1] = sizes[1]*2/3;
235  mSplitter->setSizes(sizes);
236  }
237 
238  }
239  settings()->setValue("org.custusx.help/navigationVisible", mTabWidget->isVisible());
240 }
241 
242 }//end namespace cx
void requestShowLink(const QUrl &)
virtual ~HelpWidget()
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:149
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:108
virtual QSize sizeHint() const
boost::shared_ptr< HelpEngine > HelpEnginePtr
Definition: cxHelpEngine.h:83