| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | #include <QDesktopServices>
 | 
					
						
							| 
									
										
										
										
											2014-04-24 23:58:58 +02:00
										 |  |  | #include <QShortcut>
 | 
					
						
							| 
									
										
										
										
											2014-06-06 12:10:34 -07:00
										 |  |  | #include <QFile>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "usermanual.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-06 12:10:34 -07:00
										 |  |  | #include "helpers.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | SearchBar::SearchBar(QWidget *parent): QWidget(parent) | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 	ui.setupUi(this); | 
					
						
							|  |  |  | 	#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
 | 
					
						
							|  |  |  | 	ui.findNext->setIcon(QIcon(":icons/subsurface/32x32/actions/go-down.png")); | 
					
						
							|  |  |  | 	ui.findPrev->setIcon(QIcon(":icons/subsurface/32x32/actions/go-up.png")); | 
					
						
							|  |  |  | 	ui.findClose->setIcon(QIcon(":icons/subsurface/32x32/actions/window-close.png")); | 
					
						
							|  |  |  | 	#endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	connect(ui.findNext, SIGNAL(pressed()), this, SIGNAL(searchNext())); | 
					
						
							|  |  |  | 	connect(ui.findPrev, SIGNAL(pressed()), this, SIGNAL(searchPrev())); | 
					
						
							|  |  |  | 	connect(ui.searchEdit, SIGNAL(textChanged(QString)), this, SIGNAL(searchTextChanged(QString))); | 
					
						
							|  |  |  | 	connect(ui.searchEdit, SIGNAL(textChanged(QString)), this, SLOT(enableButtons(QString))); | 
					
						
							|  |  |  | 	connect(ui.findClose, SIGNAL(pressed()), this, SLOT(hide())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SearchBar::setVisible(bool visible) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QWidget::setVisible(visible); | 
					
						
							|  |  |  | 	ui.searchEdit->setFocus(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | void SearchBar::enableButtons(const QString &s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui.findPrev->setEnabled(s.length()); | 
					
						
							|  |  |  | 	ui.findNext->setEnabled(s.length()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | UserManual::UserManual(QWidget *parent) : QWidget(parent) | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); | 
					
						
							| 
									
										
										
										
											2014-04-24 23:58:58 +02:00
										 |  |  | 	connect(closeKey, SIGNAL(activated()), this, SLOT(close())); | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	QShortcut *quitKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 	connect(quitKey, SIGNAL(activated()), qApp, SLOT(quit())); | 
					
						
							| 
									
										
										
										
											2014-04-24 23:58:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 	QAction *actionShowSearch = new QAction(this); | 
					
						
							|  |  |  | 	actionShowSearch->setShortcut(Qt::CTRL + Qt::Key_F); | 
					
						
							| 
									
										
										
										
											2014-06-25 16:07:02 +04:00
										 |  |  | 	actionShowSearch->setShortcutContext(Qt::WindowShortcut); | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 	addAction(actionShowSearch); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QAction *actionHideSearch = new QAction(this); | 
					
						
							|  |  |  | 	actionHideSearch->setShortcut(Qt::Key_Escape); | 
					
						
							| 
									
										
										
										
											2014-06-25 16:07:02 +04:00
										 |  |  | 	actionHideSearch->setShortcutContext(Qt::WindowShortcut); | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 	addAction(actionHideSearch); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-09 20:29:33 +02:00
										 |  |  | 	setWindowTitle(tr("User Manual")); | 
					
						
							| 
									
										
										
										
											2014-07-18 14:57:14 +04:00
										 |  |  | 	setWindowIcon(QIcon(":/subsurface-icon")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-09 20:29:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | 	userManual = new QWebView(this); | 
					
						
							|  |  |  | 	userManual->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 	QString searchPath = getSubsurfaceDataPath("Documentation"); | 
					
						
							| 
									
										
										
										
											2014-05-10 21:37:18 -03:00
										 |  |  | 	if (searchPath.size()) { | 
					
						
							| 
									
										
										
										
											2014-06-06 12:10:34 -07:00
										 |  |  | 		// look for localized versions of the manual first
 | 
					
						
							|  |  |  | 		QString lang = uiLanguage(NULL); | 
					
						
							|  |  |  | 		QString prefix = searchPath.append("/user-manual"); | 
					
						
							|  |  |  | 		QFile manual(prefix + "_" + lang + ".html"); | 
					
						
							|  |  |  | 		if (!manual.exists()) | 
					
						
							|  |  |  | 			manual.setFileName(prefix + "_" + lang.left(2) + ".html"); | 
					
						
							|  |  |  | 		if (!manual.exists()) | 
					
						
							|  |  |  | 			manual.setFileName(prefix + ".html"); | 
					
						
							| 
									
										
										
										
											2014-06-09 13:42:16 -07:00
										 |  |  | 		if (!manual.exists()) { | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | 			userManual->setHtml(tr("Cannot find the Subsurface manual")); | 
					
						
							| 
									
										
										
										
											2014-06-09 13:42:16 -07:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			QString urlString = QString("file:///") + manual.fileName(); | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | 			userManual->setUrl(QUrl(urlString, QUrl::TolerantMode)); | 
					
						
							| 
									
										
										
										
											2014-06-09 13:42:16 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | 		userManual->setHtml(tr("Cannot find the Subsurface manual")); | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 	searchBar = new SearchBar(this); | 
					
						
							|  |  |  | 	searchBar->hide(); | 
					
						
							|  |  |  | 	connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show())); | 
					
						
							|  |  |  | 	connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide())); | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | 	connect(userManual, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl))); | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 	connect(searchBar, SIGNAL(searchTextChanged(QString)), this, SLOT(searchTextChanged(QString))); | 
					
						
							|  |  |  | 	connect(searchBar, SIGNAL(searchNext()), this, SLOT(searchNext())); | 
					
						
							|  |  |  | 	connect(searchBar, SIGNAL(searchPrev()), this, SLOT(searchPrev())); | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QVBoxLayout *vboxLayout = new QVBoxLayout(); | 
					
						
							| 
									
										
										
										
											2014-07-16 11:58:02 +04:00
										 |  |  | 	userManual->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | 	vboxLayout->addWidget(userManual); | 
					
						
							|  |  |  | 	vboxLayout->addWidget(searchBar); | 
					
						
							|  |  |  | 	setLayout(vboxLayout); | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void UserManual::search(QString text, QWebPage::FindFlags flags = 0) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | 	if (userManual->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) { | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 		searchBar->setStyleSheet(""); | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 		searchBar->setStyleSheet("QLineEdit{background: red;}"); | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | void UserManual::searchTextChanged(const QString& text) | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 	mLastText = text; | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | 	search(text); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void UserManual::searchNext() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 	search(mLastText); | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void UserManual::searchPrev() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-30 17:45:52 -03:00
										 |  |  | 	search(mLastText, QWebPage::FindBackward); | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-11 18:01:35 -03:00
										 |  |  | void UserManual::linkClickedSlot(const QUrl& url) | 
					
						
							| 
									
										
										
										
											2014-01-09 19:21:29 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	QDesktopServices::openUrl(url); | 
					
						
							|  |  |  | } |