CustusX  15.3.4-beta
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 
50 namespace cx
51 {
52 
53 HelpWidget::HelpWidget(HelpEnginePtr engine, QWidget* parent) :
54  BaseWidget(parent, "HelpWidget", "Help"),
55  mVerticalLayout(NULL),
56  mTabWidget(NULL),
57  mEngine(engine)
58 {
59 }
60 
61 void HelpWidget::setup()
62 {
63  if (mVerticalLayout)
64  return;
65 
66  mVerticalLayout = new QVBoxLayout(this);
67  mVerticalLayout->setMargin(0);
68  mVerticalLayout->setSpacing(0);
69  this->setLayout(mVerticalLayout);
70  mTabWidget = new QTabWidget(this);
71  mTabWidget->setElideMode(Qt::ElideRight);
72 
73  QSplitter *splitter = new QSplitter(Qt::Horizontal);
74  mSplitter = splitter;
75 
76  HelpBrowser *browser = new HelpBrowser(this, mEngine);
77  connect(this, &HelpWidget::requestShowLink,
78  browser, &HelpBrowser::setSource);
79  mBrowser = browser;
80 
81  QHBoxLayout* buttonLayout = new QHBoxLayout;
82  // buttonLayout->setMargin(0);
83  mVerticalLayout->addLayout(buttonLayout);
84 
85  splitter->insertWidget(0, mTabWidget);
86  splitter->insertWidget(1, browser);
87  splitter->setStretchFactor(1, 1);
88  mVerticalLayout->addWidget(splitter);
89 
90  this->addContentWidget(mTabWidget, buttonLayout);
91  this->addSearchWidget(mTabWidget, buttonLayout);
92  this->addIndexWidget(mTabWidget, buttonLayout);
93 
94  this->addToggleTabWidgetButton(buttonLayout);
95  this->addWebNavigationButtons(buttonLayout);
96  buttonLayout->addStretch();
97 
98  browser->showHelpForKeyword("mainpage_overview");
99 
100  bool navVis = settings()->value("org.custusx.help/navigationVisible").toBool();
101 // mTabWidget->hide();
102  mTabWidget->setVisible(navVis);
103 }
104 
106 {}
107 
109 {
110  return "<html>"
111  "<h3>Experimental help</h3>"
112  "<p></p>"
113  "<p><i></i></p>"
114  "</html>";
115 }
116 
117 void HelpWidget::addContentWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
118 {
119  QHelpContentWidget* contentWidget = mEngine->engine()->contentWidget();
120  tabWidget->addTab(contentWidget, "contents");
121 
122  boost::function<void()> f = boost::bind(&QHelpContentWidget::expandToDepth, contentWidget, 2);
123  connect(mEngine->engine()->contentModel(), &QHelpContentModel::contentsCreated, f);
124  contentWidget->expandToDepth(2); // in case contents have been created
125 
126  connect(mEngine->engine()->contentWidget(), &QHelpContentWidget::linkActivated,
128 }
129 
130 void HelpWidget::addWebNavigationButtons(QBoxLayout* buttonLayout)
131 {
132  QAction* back = this->createAction(this,
133  QIcon(":/icons/open_icon_library/arrow-left-3.png"),
134  "Back", "Back to previous page",
135  SLOT(backSlot()),
136  buttonLayout, new CXSmallToolButton());
137 
138  QAction* forward = this->createAction(this,
139  QIcon(":/icons/open_icon_library/arrow-right-3.png"),
140  "Forward", "Forward to next page",
141  SLOT(forwardSlot()),
142  buttonLayout, new CXSmallToolButton());
143 
144  connect(mBrowser, SIGNAL(backwardAvailable(bool)), back, SLOT(setEnabled(bool)));
145  connect(mBrowser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setEnabled(bool)));
146 }
147 
148 void HelpWidget::backSlot()
149 {
150  mBrowser->backward();
151 }
152 
153 void HelpWidget::forwardSlot()
154 {
155  mBrowser->forward();
156 }
157 
158 void HelpWidget::addToggleTabWidgetButton(QBoxLayout* buttonLayout)
159 {
160  QAction* action = this->createAction(this,
161  QIcon(":/icons/open_icon_library/view-list-tree.png"),
162  "Toggle show navigation controls", "",
163  SLOT(toggleShowNavigationControls()),
164  NULL);
165  action->setCheckable(true);
166  CXSmallToolButton* button = new CXSmallToolButton();
167  button->setDefaultAction(action);
168  buttonLayout->addWidget(button);
169  mShowNavigationControlsAction = action;
170 }
171 
172 void HelpWidget::addIndexWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
173 {
174  mIndexWidget = new HelpIndexWidget(mEngine, this);
175  tabWidget->addTab(mIndexWidget, "index");
176 
177  connect(mIndexWidget, &HelpIndexWidget::requestShowLink,
179 }
180 
181 void HelpWidget::addSearchWidget(QTabWidget* tabWidget, QBoxLayout* buttonLayout)
182 {
183  mSearchWidget = new HelpSearchWidget(mEngine, this);
184  tabWidget->addTab(mSearchWidget, "search");
185  connect(mSearchWidget, &HelpSearchWidget::requestShowLink,
187 }
188 
189 void HelpWidget::showEvent(QShowEvent* event)
190 {
191  QWidget::showEvent(event);
192  this->setModified();
193 }
194 
195 void HelpWidget::hideEvent(QHideEvent* event)
196 {
197  QWidget::hideEvent(event);
198 }
199 
200 void HelpWidget::prePaintEvent()
201 {
202  this->setup();
203 }
204 
205 void HelpWidget::toggleShowNavigationControls()
206 {
207  if (mTabWidget->isVisible())
208  mTabWidget->hide();
209  else
210  {
211  mTabWidget->show();
212 
213  QList<int> sizes = mSplitter->sizes();
214  if (sizes[0]==0)
215  {
216  sizes[0] = sizes[1]*1/3;
217  sizes[1] = sizes[1]*2/3;
218  mSplitter->setSizes(sizes);
219  }
220 
221  }
222  settings()->setValue("org.custusx.help/navigationVisible", mTabWidget->isVisible());
223 }
224 
225 }//end namespace cx
void requestShowLink(const QUrl &)
virtual ~HelpWidget()
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:99
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:130
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:91
void showHelpForKeyword(const QString &id)
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
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
boost::shared_ptr< HelpEngine > HelpEnginePtr
Definition: cxHelpEngine.h:79