WSL/SLF GitLab Repository

Spacer.cc 2.24 KB
Newer Older
1
2
3
4
5
/*****************************************************************************/
/*  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
6
   it under the terms of the GNU General Public License as published by
7
8
9
10
11
12
   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
13
   GNU General Public License for more details.
14

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

#include "Spacer.h"

#include "src/main/constants.h"
#include "src/main/inishell.h"

24
25
26
27
//#ifdef DEBUG
	#include <iostream>
//#endif //def DEBUG

28
29
30
31
32
33
34
35
36
37
38
39
/**
 * @brief Default constructor for a Spacer.
 * @details A QSpacerItem needs separate handling everywhere (it's not a QWidget), which is why
 * we simply use an empty widget for this purpose.
 * @param[in] options XML node for the spacer with its options.
 * @param[in] parent The Spacer's parent panel/widget.
 */
Spacer::Spacer(const QDomNode &options, QWidget *parent) : QWidget(parent)
{
	int height = Cst::default_spacer_size;
	int width = Cst::default_spacer_size;
	bool success = true;
40
	const QDomElement op_el( options.toElement() );
41
	/* look for "height" or "h" */
42
43
44
45
	if (!op_el.attribute("height").isNull())
		height = op_el.attribute("height").toInt(&success);
	if (!success && !op_el.attribute("h").isNull())
		height = op_el.attribute("h").toInt(&success);
46
	if (!success)
47
		topLog(tr(R"(XML error: Could not parse height for spacer element)"), "error");
48
	/* look for "width" or "w" */
49
50
51
52
53
	success = true;
	if (!op_el.attribute("width").isNull())
		width = op_el.attribute("width").toInt(&success);
	if (!success && !op_el.attribute("w").isNull())
		width = op_el.attribute("w").toInt(&success);
54
	if (!success)
55
		topLog(tr(R"(XML error: Could not parse width for spacer element)"), "error");
56
57
	this->setFixedSize(width, height);
}