1 /**********************************************************************************************
2     Copyright (C) 2018 Oliver Eichler <oliver.eichler@gmx.de>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 **********************************************************************************************/
18 
19 #include "help/CHelpBrowser.h"
20 #include <QtHelp>
21 
CHelpBrowser(QHelpEngine * helpEngine,QWidget * parent)22 CHelpBrowser::CHelpBrowser(QHelpEngine *helpEngine, QWidget *parent)
23     : QTextBrowser(parent)
24     , engine(helpEngine)
25 {
26     connect(engine->contentWidget(), &QHelpContentWidget::linkActivated, this, &CHelpBrowser::setSource);
27     connect(engine->indexWidget(), &QHelpIndexWidget::linkActivated, this, &CHelpBrowser::setSource);
28     connect(engine->searchEngine()->resultWidget(), &QHelpSearchResultWidget::requestShowLink, this, &CHelpBrowser::setSource);
29 }
30 
setSource(const QUrl & url)31 void CHelpBrowser::setSource(const QUrl& url)
32 {
33     if(url.scheme().startsWith("http"))
34     {
35         QDesktopServices::openUrl(url);
36         return;
37     }
38     QTextBrowser::setSource(url);
39 }
40 
loadResource(int type,const QUrl & name)41 QVariant CHelpBrowser::loadResource(int type, const QUrl &name)
42 {
43     qDebug() << name;
44     if (name.scheme() == "qthelp")
45     {
46         return QVariant(engine->fileData(name));
47     }
48     else
49     {
50         return QTextBrowser::loadResource(type, name);
51     }
52 }
53