helpWidget.cc 3.96 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 19 20 21 22 23
	: QMainWindow(parent),
	searchWidget_(0),
	textWindow_(0),
	helpEngine_(0) {

	setupUi(this);

24 25
	homeSite_ = _homeSite;

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

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

32 33 34 35 36 37 38 39 40 41 42 43
	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"));
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

	helpEngine_ = new QHelpEngine(filename, this);

	helpEngine_->setupData();

    textWindow_ = new HelpBrowser(helpEngine_, this);

    gridLayout_->addWidget(helpEngine_->contentWidget(), 0, 0);
    gridLayout_->addWidget(textWindow_, 0, 1);

    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 );

	searchWidget_->resize(this->size().width(), floor(this->size().height() / 3));

	results_ = new QListWidget();

65 66
	searchWidget_->setWidget(helpEngine_->indexWidget());
	//searchWidget_->setWidget(results_);
67 68 69 70 71 72 73

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


    // Entry in tree view has been clicked
    connect(helpEngine_->contentWidget(), SIGNAL(linkActivated(const QUrl&)),
74 75 76 77
            textWindow_, SLOT(load(const QUrl&)));

    connect(helpEngine_->indexWidget(), SIGNAL(linkActivated(const QUrl&, const QString&)),
            textWindow_, SLOT(load(const QUrl&, const QString&)));
78 79

    // Entry in results view (search) has been clicked
80 81
    //connect(results_, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
    //		textWindow_, SLOT(openFoundSite(QListWidgetItem*)));
82 83 84 85 86 87 88 89 90 91

    // Search button
    connect(searchButton_, SIGNAL(clicked()), this, SLOT(searchItems()));

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

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

92 93 94
    // Forward button
    connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome()));

95
    // Source has been reloaded
96 97 98 99 100
    connect(textWindow_, SIGNAL(urlChanged(const QUrl&)), this, SLOT(update(const QUrl&)));

    // Register documentation (if not registered yet)
    helpEngine_->registerDocumentation(filename);
    helpEngine_->setCurrentFilter("");
101 102

    // Load main page
103 104 105 106 107 108
    textWindow_->load(QUrl(homeSite_));
}

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

	homeSite_ = _homeSite;
109 110
}

111
void HelpWidget::update(const QUrl& /* url */) {
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

	updateButtons();
}

void HelpWidget::goForward() {

	textWindow_->forward();

	updateButtons();
}

void HelpWidget::goBack() {

	textWindow_->backward();

	updateButtons();
}

130 131 132 133 134 135 136
void HelpWidget::goHome() {

	textWindow_->load(homeSite_);

	updateButtons();
}

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
void HelpWidget::updateButtons() {

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

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

void HelpWidget::searchItems() {

154
	QMap<QString, QUrl> results = helpEngine_->linksForIdentifier(searchButton_->text());
155

156
	std::cerr << "Found: " << results.size() << std::endl;
157 158 159 160

	searchWidget_->show();
}

Jan Möbius's avatar
Jan Möbius committed
161
void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) {
162 163

}
Mike Kremer's avatar
Mike Kremer committed
164 165 166 167 168 169 170 171

HelpWidget::~HelpWidget() {

	delete searchWidget_;
	delete results_;
	delete textWindow_;
	delete helpEngine_;
}