helpWidget.cc 7.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision: 83 $                                                         *
 *   $Author: moebius $                                                      *
 *   $Date: 2009-02-27 17:31:45 +0100 (Fr, 27. Feb 2009) $                   *
 *                                                                           *
\*===========================================================================*/


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * helpWidget.cc
 *
 *  Created on: Apr 7, 2009
 *      Author: kremer
 */

#include "helpWidget.hh"

#include <OpenFlipper/common/GlobalOptions.hh>

#include <iostream>

#include <QTextStream>

59
HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
60
61
	: QMainWindow(parent),
	searchWidget_(0),
62
	tabWidget_(0),
63
	textWindow_(0),
64
65
	helpEngine_(0),
	searchEngine_(0) {
66
67
68

	setupUi(this);

69
70
	homeSite_ = _homeSite;

71
72
73
	QString filename = QString(OpenFlipper::Options::helpDirStr());
	filename += OpenFlipper::Options::dirSeparator();
	filename += "Help.qhc";
74

75
76
77
78
79
80
81
82
83
84
85
86
	QString iconPath = QString(OpenFlipper::Options::iconDirStr());
#ifdef WIN32
	iconPath += "\\";
#else
	iconPath += "/";
#endif

	// Set Buttons
	backButton_->setIcon(QIcon(iconPath+"arrow-left.png"));
	forwardButton_->setIcon(QIcon(iconPath+"arrow-right.png"));
	homeButton_->setIcon(QIcon(iconPath+"go-home.png"));
	searchButton_->setIcon(QIcon(iconPath+"edit-find.png"));
87

88
89
	tabWidget_ = new QTabWidget(this);

90
91
92
93
	helpEngine_ = new QHelpEngine(filename, this);

	helpEngine_->setupData();

94
95
	searchEngine_ = new QHelpSearchEngine(helpEngine_, this);

96
    textWindow_ = new HelpBrowser(helpEngine_, this);
97

98
    homeIndex_ = tabWidget_->addTab(textWindow_, tr("Home"));
99

100
101
    gridLayout_->addWidget(helpEngine_->contentWidget(), 1, 0);
    gridLayout_->addWidget(tabWidget_, 1, 1);
102
103
104
105
106
107
108
109

    gridLayout_->setColumnStretch(0, 1);
    gridLayout_->setColumnStretch(1, 3);

    // Search popup at bottom of window
    searchWidget_ = new QDockWidget(tr("Search results"), this);
	searchWidget_->setFeatures( QDockWidget::DockWidgetClosable );

Jan Möbius's avatar
Jan Möbius committed
110
	searchWidget_->resize(this->size().width(), floor( double(this->size().height() / 3)) );
111

112
	searchWidget_->setWidget(searchEngine_->queryWidget());
113
	//searchWidget_->setWidget(results_);
114
115
116
117
118
119
120

	searchWidget_->hide();
	addDockWidget(Qt::BottomDockWidgetArea, searchWidget_);


    // Entry in tree view has been clicked
    connect(helpEngine_->contentWidget(), SIGNAL(linkActivated(const QUrl&)),
121
            this, SLOT(linkActivated(const QUrl&)));
122

123

124
125
    // Search button
    connect(searchButton_, SIGNAL(clicked()), this, SLOT(showSearchWidget()));
126
127

    // Search button
128
129
130
131
132
133
134
135
    connect(searchEngine_->queryWidget(), SIGNAL(search()), this, SLOT(startSearch()));

    // Show results if search is finished
    connect(searchEngine_, SIGNAL(searchingFinished(int)), this, SLOT(showResults(int)));

    // Show results if search is finished
    connect(searchEngine_->resultWidget(), SIGNAL(requestShowLink(const QUrl&)),
    		this, SLOT(showFoundSite(const QUrl&)));
136
137
138
139
140
141
142

    // Back button
    connect(backButton_, SIGNAL(clicked()), this, SLOT(goBack()));

    // Forward button
    connect(forwardButton_, SIGNAL(clicked()), this, SLOT(goForward()));

143
144
145
    // Forward button
    connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome()));

146
    // Source has been reloaded
147
148
    connect(textWindow_, SIGNAL(urlChanged(const QUrl&)), this, SLOT(update(const QUrl&)));

149
150
    // Register documentation
    helpEngine_->registerDocumentation(filename);
151
152

    // Load main page
153
154
155
    textWindow_->open(QUrl(homeSite_));
}

156
157
158
159
160
161
void HelpWidget::linkActivated(const QUrl& _url) {

	textWindow_->open(_url);
	tabWidget_->setCurrentIndex(homeIndex_);
}

162
163
164
void HelpWidget::startSearch() {

	searchEngine_->search(searchEngine_->queryWidget()->query());
165
166
167
168
169
}

void HelpWidget::setHomeSite(const QString& _homeSite) {

	homeSite_ = _homeSite;
170
171
}

172
173
174
175
176
177
void HelpWidget::showFoundSite(const QUrl& _url) {

	textWindow_->open(_url);
	tabWidget_->setCurrentIndex(homeIndex_);
}

178
void HelpWidget::update(const QUrl& /* url */) {
179
180
181
182
183
184
185
186

	updateButtons();
}

void HelpWidget::goForward() {

	textWindow_->forward();

187
188
	tabWidget_->setCurrentIndex(homeIndex_);

189
190
191
192
193
194
195
	updateButtons();
}

void HelpWidget::goBack() {

	textWindow_->backward();

196
197
	tabWidget_->setCurrentIndex(homeIndex_);

198
199
200
	updateButtons();
}

201
202
void HelpWidget::goHome() {

203
	textWindow_->open(homeSite_);
204

205
206
	tabWidget_->setCurrentIndex(homeIndex_);

207
208
209
	updateButtons();
}

210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
void HelpWidget::updateButtons() {

	if(!textWindow_->isBackwardAvailable()) {
		backButton_->setEnabled(false);
	} else {
		backButton_->setEnabled(true);
	}

	if(!textWindow_->isForwardAvailable()) {
		forwardButton_->setEnabled(false);
	} else {
		forwardButton_->setEnabled(true);
	}
}

225
void HelpWidget::showSearchWidget() {
226

227
228
	searchWidget_->show();
}
229

230
void HelpWidget::showResults(int /*_hits*/) {
231

232
233
	searchWidget_->hide();

234
	int resultsTabIndex_ = tabWidget_->addTab(searchEngine_->resultWidget(), tr("Results") );
235
	tabWidget_->setCurrentIndex(resultsTabIndex_);
236
237
}

Jan Möbius's avatar
Jan Möbius committed
238
void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) {
239
240

}
Mike Kremer's avatar
Mike Kremer committed
241
242
243
244
245
246

HelpWidget::~HelpWidget() {

	delete searchWidget_;
	delete textWindow_;
}