helpWidget.cc 4.5 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, const QString& _baseURL)
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
55
56
57
	searchEngine_ = new QHelpSearchEngine(helpEngine_, this);

    textWindow_ = new HelpBrowser(helpEngine_, _baseURL, this);

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

    gridLayout_->addWidget(helpEngine_->contentWidget(), 0, 0);
60
    gridLayout_->addWidget(tabWidget_, 0, 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
            textWindow_, SLOT(open(const QUrl&)));
81
82

    connect(helpEngine_->indexWidget(), SIGNAL(linkActivated(const QUrl&, const QString&)),
83
84
            textWindow_, SLOT(open(const QUrl&, const QString&)));

85

86
87
    // Search button
    connect(searchButton_, SIGNAL(clicked()), this, SLOT(showSearchWidget()));
88
89

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

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

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

105
106
107
    // Forward button
    connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome()));

108
    // Source has been reloaded
109
110
    connect(textWindow_, SIGNAL(urlChanged(const QUrl&)), this, SLOT(update(const QUrl&)));

111
112

    // Load main page
113
114
115
116
117
118
    textWindow_->open(QUrl(homeSite_));
}

void HelpWidget::startSearch() {

	searchEngine_->search(searchEngine_->queryWidget()->query());
119
120
121
122
123
}

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

	homeSite_ = _homeSite;
124
125
}

126
127
128
129
130
131
void HelpWidget::showFoundSite(const QUrl& _url) {

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

132
void HelpWidget::update(const QUrl& /* url */) {
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

	updateButtons();
}

void HelpWidget::goForward() {

	textWindow_->forward();

	updateButtons();
}

void HelpWidget::goBack() {

	textWindow_->backward();

	updateButtons();
}

151
152
void HelpWidget::goHome() {

153
	textWindow_->open(homeSite_);
154
155
156
157

	updateButtons();
}

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
void HelpWidget::updateButtons() {

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

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

173
void HelpWidget::showSearchWidget() {
174

175
176
	searchWidget_->show();
}
177

178
void HelpWidget::showResults(int /*_hits*/) {
179

180
181
182
183
	searchWidget_->hide();

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

Jan Möbius's avatar
Jan Möbius committed
186
void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) {
187
188

}
Mike Kremer's avatar
Mike Kremer committed
189
190
191
192
193
194

HelpWidget::~HelpWidget() {

	delete searchWidget_;
	delete textWindow_;
}