WSL/SLF GitLab Repository

AboutWindow.cc 5.17 KB
Newer Older
Mathias Bavay's avatar
Mathias Bavay committed
1
//SPDX-License-Identifier: GPL-3.0-or-later
2
3
4
5
6
/*****************************************************************************/
/*  Copyright 2019 WSL Institute for Snow and Avalanche Research  SLF-DAVOS  */
/*****************************************************************************/
/* This file is part of INIshell.
   INIshell is free software: you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
9
10
11
12
13
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   INIshell is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15

16
17
   You should have received a copy of the GNU General Public License
   along with INIshell.  If not, see <http://www.gnu.org/licenses/>.
18
19
*/

20
21
22
23
#include <src/gui/AboutWindow.h>
#include <src/main/common.h>
#include <src/main/constants.h>
#include <src/main/inishell.h>
Michael Reisecker's avatar
Michael Reisecker committed
24

25
#include <QKeySequence>
Michael Reisecker's avatar
Michael Reisecker committed
26
#include <QFile>
27
28
#include <QGuiApplication>
#include <QScreen>
Michael Reisecker's avatar
Michael Reisecker committed
29
30
#include <QVBoxLayout>

31
32
33
34
#ifdef DEBUG
	#include <iostream>
#endif

35
36
37
38
39
/**
 * @class AboutWindow
 * @brief Constructor for the About window.
 * @param[in] parent The window's parent.
 */
Michael Reisecker's avatar
Michael Reisecker committed
40
41
AboutWindow::AboutWindow(QWidget *parent) : QWidget(parent, Qt::Window)
{
42
	auto *textbox( new QTextBrowser );
Michael Reisecker's avatar
Michael Reisecker committed
43
44
45
46
	textbox->setReadOnly(true);
	textbox->setTextInteractionFlags(Qt::TextBrowserInteraction);
	textbox->setOpenExternalLinks(true);

47
	setAboutText(textbox); //fill with text
Michael Reisecker's avatar
Michael Reisecker committed
48

49
	auto *main_layout( new QVBoxLayout );
Michael Reisecker's avatar
Michael Reisecker committed
50
51
52
	main_layout->addWidget(textbox);
	this->setLayout(main_layout);

53
	/* center the window on screen */
Michael Reisecker's avatar
Michael Reisecker committed
54
	this->setFixedSize(Cst::width_help_about, Cst::height_help_about);
55
	QScreen *screen_object( QGuiApplication::primaryScreen() );
56
57
58
	QSize screen(screen_object->geometry().width(), screen_object->geometry().height());
	this->move(screen.width() / 2 - Cst::width_help_about / 2,
	    screen.height() / 2 - Cst::height_help_about / 2);
59

60
61
	this->setWindowFlag(Qt::Dialog); //prevent double title bar on osX
	this->setWindowFlag(Qt::WindowStaysOnTopHint);
62
	this->setWindowTitle(tr("About") + " ~ " + QCoreApplication::applicationName());
63
64
}

Michael Reisecker's avatar
Michael Reisecker committed
65
/**
66
67
68
 * @brief Catch key press events in the About window..
 * @details Close the About window on pressing ESC, and set the usual
 * shortcuts to show our windows.
Michael Reisecker's avatar
Michael Reisecker committed
69
 * @param[in] event The key press event that is received.
Michael Reisecker's avatar
Michael Reisecker committed
70
71
72
 */
void AboutWindow::keyPressEvent(QKeyEvent *event)
{
73
	if (event->key() == Qt::Key_Escape || keyToSequence(event) == QKeySequence::Close) {
Michael Reisecker's avatar
Michael Reisecker committed
74
		this->close();
75
76
77
78
79
80
	} else if (keyToSequence(event) == QKeySequence::Print) {
		emit getMainWindow()->viewPreview();
	} else if (event->modifiers() == Qt::CTRL && event->key() == Qt::Key_L) {
		getMainWindow()->getLogger()->show();
		getMainWindow()->getLogger()->raise();
	}
Michael Reisecker's avatar
Michael Reisecker committed
81
82
}

83
84
85
86
87
/**
 * @brief Fill the About window with HTLM Text.
 * @details This is hardcoded to be able to conveniently access runtime information (e. g. version info).
 * @param[in] textbox The textbox to fill.
 */
88
89
void AboutWindow::setAboutText(QTextBrowser *textbox)
{ //hardcoded for easy access to version
90
	textbox->setHtml("<a href=\"https://gitlabext.wsl.ch/snow-models/inishell\"><center><img src=\":/icons/inishell_192.ico\" height=\"92\" width=\"92\"></a></center> \
91
	    <center><b>INIshell version " + QString(APP_VERSION_STR) + "</b><br> \
Michael Reisecker's avatar
Michael Reisecker committed
92
	    &copy; WSL-Institut für Schnee-und Lawinenforschung <a href=\"https://www.slf.ch\">SLF</a> 2019-2021<br> \
93
		<a href=\"https://gitlabext.wsl.ch/snow-models/inishell\">Project page</a> &middot; <a href=\"https://gitlabext.wsl.ch/snow-models/inishell/-/blob/master/CHANGELOG.md\">Release notes</a> &middot; <a href=\"https://gitlabext.wsl.ch/snow-models/inishell/-/issues\">Bug tracker</a> &middot; <a href=\"https://gitlabext.wsl.ch/snow-models/inishell/-/tree/master\">Source code</a><br></center> \
Michael Reisecker's avatar
Michael Reisecker committed
94
	    Original version: <i>Michael Reisecker, 2019 - 2021</i><br> \
95
96
	    Inspired by INIshell v1: <i>Mathias Bavay, Thomas Egger & Daniela Korhammer, 2011</i><br> \
		Built with <a href=\"https://www.qt.io/\">Qt</a>,  \
97
	    arithmetic evaluations by <a href=\"https://github.com/codeplea/tinyexpr\">tinyexpr</a>, lines numbering from Qt under a <a href=\"https://opensource.org/licenses/BSD-3-Clause\">BSD</a> license.<br> \
98
	    Icons by <a href=\"https://github.com/KDE/breeze-icons\">Breeze-icons</a> and <a href=\"https://icons8.com\">Icons8</a>.<br><hr> \
99
100
	    <center><i>INIshell is free software: you can redistribute it and/or modify \
	    it under the terms of the \
101
	    <b><a href=\"http://www.gnu.org/licenses/\">GNU General Public License</a></b> \
102
103
	    as published by the Free Software Foundation, \
	    either version 3 of the License, or \
104
	    (at your option) any later version.<br><br> \
105
106
107
108
	    INIshell is distributed in the hope that \
	    it will be useful, but \
	    WITHOUT ANY WARRANTY; without even the implied warranty of \
	    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the \
109
	    GNU General Public License for more details.<br><br> \
110
	    <a href=\"https://www.slf.ch\"><img src=\":/icons/slf.svg\" height=\"92\" width=\"92\"></a></center> \
111
	");
Michael Reisecker's avatar
Michael Reisecker committed
112
}