CustusX  16.12
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, "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  return QSize(250,30);
117 }
118 
119 
120 void HelpWidget::addContentWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
121 {
122  QHelpContentWidget* contentWidget = mEngine->engine()->contentWidget();
123  tabWidget->addTab(contentWidget, "contents");
124 
125  boost::function<void()> f = boost::bind(&QHelpContentWidget::expandToDepth, contentWidget, 2);
126  connect(mEngine->engine()->contentModel(), &QHelpContentModel::contentsCreated, f);
127  contentWidget->expandToDepth(2); // in case contents have been created
128 
129  connect(mEngine->engine()->contentWidget(), &QHelpContentWidget::linkActivated,
131 }
132 
133 void HelpWidget::addWebNavigationButtons(QBoxLayout* buttonLayout)
134 {
135  QAction* back = this->createAction(this,
136  QIcon(":/icons/open_icon_library/arrow-left-3.png"),
137  "Back", "Back to previous page",
138  SLOT(backSlot()),
139  buttonLayout, new CXSmallToolButton());
140 
141  QAction* forward = this->createAction(this,
142  QIcon(":/icons/open_icon_library/arrow-right-3.png"),
143  "Forward", "Forward to next page",
144  SLOT(forwardSlot()),
145  buttonLayout, new CXSmallToolButton());
146 
147  connect(mBrowser, SIGNAL(backwardAvailable(bool)), back, SLOT(setEnabled(bool)));
148  connect(mBrowser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setEnabled(bool)));
149 }
150 
151 void HelpWidget::addWebButton(QBoxLayout* buttonLayout)
152 {
153  this->createAction2(this,
154  QIcon(":/icons/open_icon_library/applications-internet.png"),
155  "Web", "Open Web Documentation",
156  &HelpWidget::onGotoDocumentation,
157  buttonLayout, new CXSmallToolButton());
158 }
159 
160 void HelpWidget::onGotoDocumentation()
161 {
163  QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
164 }
165 
166 void HelpWidget::backSlot()
167 {
168  mBrowser->backward();
169 }
170 
171 void HelpWidget::forwardSlot()
172 {
173  mBrowser->forward();
174 }
175 
176 void HelpWidget::addToggleTabWidgetButton(QBoxLayout* buttonLayout)
177 {
178  QAction* action = this->createAction(this,
179  QIcon(":/icons/open_icon_library/view-list-tree.png"),
180  "Toggle show navigation controls", "",
181  SLOT(toggleShowNavigationControls()),
182  NULL);
183  action->setCheckable(true);
184  CXSmallToolButton* button = new CXSmallToolButton();
185  button->setDefaultAction(action);
186  buttonLayout->addWidget(button);
187  mShowNavigationControlsAction = action;
188 }
189 
190 void HelpWidget::addIndexWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
191 {
192  mIndexWidget = new HelpIndexWidget(mEngine, this);
193  tabWidget->addTab(mIndexWidget, "index");
194 
195  connect(mIndexWidget, &HelpIndexWidget::requestShowLink,
197 }
198 
199 void HelpWidget::addSearchWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
200 {
201  mSearchWidget = new HelpSearchWidget(mEngine, this);
202  tabWidget->addTab(mSearchWidget, "search");
203  connect(mSearchWidget, &HelpSearchWidget::requestShowLink,
205 }
206 
207 void HelpWidget::showEvent(QShowEvent* event)
208 {
209  QWidget::showEvent(event);
210  this->setModified();
211 }
212 
213 void HelpWidget::hideEvent(QHideEvent* event)
214 {
215  QWidget::hideEvent(event);
216 }
217 
218 void HelpWidget::prePaintEvent()
219 {
220  this->setup();
221 }
222 
223 void HelpWidget::toggleShowNavigationControls()
224 {
225  if (mTabWidget->isVisible())
226  mTabWidget->hide();
227  else
228  {
229  mTabWidget->show();
230 
231  QList<int> sizes = mSplitter->sizes();
232  if (sizes[0]==0)
233  {
234  sizes[0] = sizes[1]*1/3;
235  sizes[1] = sizes[1]*2/3;
236  mSplitter->setSizes(sizes);
237  }
238 
239  }
240  settings()->setValue("org.custusx.help/navigationVisible", mTabWidget->isVisible());
241 }
242 
243 }//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: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:82