helpWidget.cc 4.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * helpWidget.cc
 *
 *  Created on: Apr 7, 2009
 *      Author: kremer
 */

#include "helpWidget.hh"

#include <OpenFlipper/common/GlobalOptions.hh>

#include <iostream>

#include <QTextStream>

16
HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
17
18
	: QMainWindow(parent),
	searchWidget_(0),
19
	tabWidget_(0),
20
	textWindow_(0),
21
22
	helpEngine_(0),
	searchEngine_(0) {
23
24
25

	setupUi(this);

26
27
	homeSite_ = _homeSite;

28
29
30
31
32
33
	QString filename = QString(OpenFlipper::Options::applicationDirStr());
	filename += "/Help/Help.qhc";

	QString stylesheet = QString(OpenFlipper::Options::applicationDirStr());
	stylesheet += "/Help/acg_style.css";

34
35
36
37
38
39
40
41
42
43
44
45
	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"));
46

47
48
	tabWidget_ = new QTabWidget(this);

49
50
51
52
	helpEngine_ = new QHelpEngine(filename, this);

	helpEngine_->setupData();

53
54
	searchEngine_ = new QHelpSearchEngine(helpEngine_, this);

55
    textWindow_ = new HelpBrowser(helpEngine_, this);
56
57

    homeIndex_ = tabWidget_->addTab(textWindow_, "Home");
58

59
60
    gridLayout_->addWidget(helpEngine_->contentWidget(), 1, 0);
    gridLayout_->addWidget(tabWidget_, 1, 1);
61
62
63
64
65
66
67
68

    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
69
	searchWidget_->resize(this->size().width(), floor( double(this->size().height() / 3)) );
70

71
	searchWidget_->setWidget(searchEngine_->queryWidget());
72
	//searchWidget_->setWidget(results_);
73
74
75
76
77
78
79

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


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

82

83
84
    // Search button
    connect(searchButton_, SIGNAL(clicked()), this, SLOT(showSearchWidget()));
85
86

    // Search button
87
88
89
90
91
92
93
94
    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&)));
95
96
97
98
99
100
101

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

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

102
103
104
    // Forward button
    connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome()));

105
    // Source has been reloaded
106
107
    connect(textWindow_, SIGNAL(urlChanged(const QUrl&)), this, SLOT(update(const QUrl&)));

108
109
    // Register documentation
    helpEngine_->registerDocumentation(filename);
110
111

    // Load main page
112
113
114
    textWindow_->open(QUrl(homeSite_));
}

115
116
117
118
119
120
void HelpWidget::linkActivated(const QUrl& _url) {

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

121
122
123
void HelpWidget::startSearch() {

	searchEngine_->search(searchEngine_->queryWidget()->query());
124
125
126
127
128
}

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

	homeSite_ = _homeSite;
129
130
}

131
132
133
134
135
136
void HelpWidget::showFoundSite(const QUrl& _url) {

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

137
void HelpWidget::update(const QUrl& /* url */) {
138
139
140
141
142
143
144
145

	updateButtons();
}

void HelpWidget::goForward() {

	textWindow_->forward();

146
147
	tabWidget_->setCurrentIndex(homeIndex_);

148
149
150
151
152
153
154
	updateButtons();
}

void HelpWidget::goBack() {

	textWindow_->backward();

155
156
	tabWidget_->setCurrentIndex(homeIndex_);

157
158
159
	updateButtons();
}

160
161
void HelpWidget::goHome() {

162
	textWindow_->open(homeSite_);
163

164
165
	tabWidget_->setCurrentIndex(homeIndex_);

166
167
168
	updateButtons();
}

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
void HelpWidget::updateButtons() {

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

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

184
void HelpWidget::showSearchWidget() {
185

186
187
	searchWidget_->show();
}
188

189
void HelpWidget::showResults(int /*_hits*/) {
190

191
192
193
194
	searchWidget_->hide();

	int resultsTabIndex_ = tabWidget_->addTab(searchEngine_->resultWidget(), "Results");
	tabWidget_->setCurrentIndex(resultsTabIndex_);
195
196
}

Jan Möbius's avatar
Jan Möbius committed
197
void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) {
198
199

}
Mike Kremer's avatar
Mike Kremer committed
200
201
202
203
204
205

HelpWidget::~HelpWidget() {

	delete searchWidget_;
	delete textWindow_;
}