1 /*
2 Copyright © 2011-13 Qtrac Ltd. All rights reserved.
3 This program or module is free software: you can redistribute it
4 and/or modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation, either version 2 of
6 the License, or (at your option) any later version. This program is
7 distributed in the hope that it will be useful, but WITHOUT ANY
8 WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10 for more details.
11 */
12
13 #include "helpform.hpp"
14 #include <QApplication>
15 #include <QFile>
16 #include <QKeySequence>
17 #include <QSettings>
18 #include <QShortcut>
19 #include <QTextBrowser>
20 #include <QTextStream>
21
22
HelpForm(const QString & language,QWidget * parent)23 HelpForm::HelpForm(const QString &language, QWidget *parent)
24 : QMainWindow(parent)
25 {
26 QTextBrowser *viewer = new QTextBrowser;
27 viewer->setOpenExternalLinks(true);
28 QString filename = QString(":/help_%1.html").arg(language);
29 if (!QFile::exists(filename))
30 filename = ":/help.html";
31 QFile file(filename);
32 file.open(QIODevice::ReadOnly|QIODevice::Text);
33 QTextStream in(&file);
34 in.setCodec("UTF-8");
35 viewer->setHtml(in.readAll());
36 viewer->setReadOnly(true);
37 setCentralWidget(viewer);
38 (void) new QShortcut(QKeySequence("Escape"), this, SLOT(close()));
39 QPoint pos(0, 0);
40 if (parent)
41 pos = parent->pos();
42 move(pos);
43 resize(640, 480);
44 QSettings settings;
45 restoreGeometry(settings.value("HelpForm/Geometry").toByteArray());
46 setWindowTitle(tr("%1 — Help").arg(qApp->applicationName()));
47 }
48
49
closeEvent(QCloseEvent *)50 void HelpForm::closeEvent(QCloseEvent *)
51 {
52 QSettings settings;
53 settings.setValue("HelpForm/Geometry", saveGeometry());
54 }
55