WSL/SLF GitLab Repository

HelpWindow.cc 3.3 KB
Newer Older
Michael Reisecker's avatar
Michael Reisecker committed
1
#include "HelpWindow.h"
2
#include "AboutWindow.h"
Michael Reisecker's avatar
Michael Reisecker committed
3
4
5
6
7
#include "src/main/dimensions.h"
#include "src/main/inishell.h"
#include "src/main/XMLReader.h"

#include <QCoreApplication>
8
#include <QDesktopServices>
9
#include <QMenuBar>
Michael Reisecker's avatar
Michael Reisecker committed
10
11
12
13
14

#ifdef DEBUG
	#include <iostream>
#endif

15
16
HelpWindow::HelpWindow(QMainWindow *parent) : QMainWindow(parent)
{
Michael Reisecker's avatar
Michael Reisecker committed
17
18

	/* create a scroll area and put a Group in it */
19
20
	help_tab_ = new SectionTab();
	this->setCentralWidget(help_tab_);
Michael Reisecker's avatar
Michael Reisecker committed
21

Michael Reisecker's avatar
Michael Reisecker committed
22
23
	dim::setDimensions(this, dim::HELP);
	this->setWindowTitle(tr("Help") + " ~ " + QCoreApplication::applicationName());
24
25

	createMenu();
Michael Reisecker's avatar
Michael Reisecker committed
26
27
}

28
29
void HelpWindow::loadHelp(const bool &dev)
{
Michael Reisecker's avatar
Michael Reisecker committed
30
	static bool is_loaded = false;
Michael Reisecker's avatar
Michael Reisecker committed
31
32
	if (!is_loaded | dev) {
		help_tab_->clear();
Michael Reisecker's avatar
Michael Reisecker committed
33
34
		XMLReader xmlr;
		QString err;
Michael Reisecker's avatar
Michael Reisecker committed
35
36
37
38
		QString help_file( "help.xml" );
		if (dev)
			help_file = "help_dev.xml";
		xmlr.read(":doc/" + help_file, err);
Michael Reisecker's avatar
Michael Reisecker committed
39
		QDomDocument xml(xmlr.getXml());
40
41
		buildGui(xml, help_tab_);
		is_loaded = true && !dev; //reload after opening dev
Michael Reisecker's avatar
Michael Reisecker committed
42
	}
43

44
45
	view_dev_help_->setChecked(dev);
	view_user_guide_->setChecked(!dev);
Michael Reisecker's avatar
Michael Reisecker committed
46
47
	this->show();
	this->raise();
Michael Reisecker's avatar
Michael Reisecker committed
48
}
49
50
51
52
53
54
55
56
57
58
59

/**
 * @brief Event listener for the ESC key.
 * @details Close the help on pressing ESC.
 * @param event The key press event that is received.
 */
void HelpWindow::keyPressEvent(QKeyEvent *event)
{
	if (event->key() == Qt::Key_Escape || keyToSequence(event) == QKeySequence::Close)
		this->close();
}
60
61
62

void HelpWindow::createMenu()
{
63
64
65
66
67
68
69
	/* FILE menu */
	QMenu *menu_file = this->menuBar()->addMenu(tr("&File"));
	auto *file_bugreport_ = new QAction(tr("File &bug report..."), menu_file);
	menu_file->addAction(file_bugreport_);
	connect(file_bugreport_, &QAction::triggered,
		[]{ QDesktopServices::openUrl(QUrl("https://models.slf.ch/p/inishell-ng/issues/")); });
	menu_file->addSeparator();
70
71
72
73
74
	auto *file_close = new QAction(getIcon("application-exit"), tr("&Close"), menu_file);
	file_close->setShortcut(QKeySequence::Quit);
	file_close->setMenuRole(QAction::QuitRole);
	menu_file->addAction(file_close);
	connect(file_close, &QAction::triggered, this, [=]{ this->close(); });
75

76
77
	/* VIEW menu */
	QMenu *menu_view = this->menuBar()->addMenu(tr("&View"));
78
	view_user_guide_ = new QAction(tr("&User guide"), menu_view); //no icon to get checkboxes
79
80
81
82
83
	view_user_guide_->setCheckable(true);
	view_user_guide_->setChecked(true);
	menu_view->addAction(view_user_guide_);
	view_user_guide_->setShortcut(QKeySequence::HelpContents);
	connect(view_user_guide_, &QAction::triggered, this, [=]{ loadHelp(); });
84
	view_dev_help_ = new QAction(tr("&Developer's guide"), menu_view);
85
86
87
	view_dev_help_->setCheckable(true);
	menu_view->addAction(view_dev_help_);
	connect(view_dev_help_, &QAction::triggered, this, [=]{ loadHelp(true); });
88
	menu_view->addSeparator();
89
90
91
92
93
	auto *help_about = new QAction(getIcon("help-about"), tr("&About"), menu_view);
	help_about->setMenuRole(QAction::AboutRole);
	menu_view->addAction(help_about);
	connect(help_about, &QAction::triggered, this, &HelpWindow::helpAbout);
	help_about->setShortcut(QKeySequence::WhatsThis);
94
95
96
97
	auto *show_paper = new QAction(tr("Show &paper..."), menu_view);
	menu_view->addAction(show_paper);
	connect(show_paper, &QAction::triggered, this, [=]{ QDesktopServices::openUrl(QUrl(":doc/paper.pdf")); });
	show_paper->setEnabled(false);
98
}
99
100
101
102
103
104
105

void HelpWindow::helpAbout()
{
	static auto *about = new AboutWindow(this);
	about->show();
	about->raise();
}