WSL/SLF GitLab Repository

Atomic.h 3.51 KB
Newer Older
Michael Reisecker's avatar
Michael Reisecker committed
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
Michael Reisecker's avatar
Michael Reisecker committed
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.
Michael Reisecker's avatar
Michael Reisecker committed
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/>.
Michael Reisecker's avatar
Michael Reisecker committed
17
18
19
20
21
22
23
*/

/*
 * The base class for input panels handling some common functionality.
 * 2019-10
 */

24
25
26
#ifndef ATOMIC_H
#define ATOMIC_H

27
#include "src/gui_elements/Helptext.h"
Michael Reisecker's avatar
Michael Reisecker committed
28
#include "src/main/common.h"
29
#include "src/main/constants.h"
Michael Reisecker's avatar
Michael Reisecker committed
30
#include "src/main/INIParser.h"
31

32
#include <QFont>
33
#include <QHBoxLayout>
34
#include <QMenu>
35
36
#include <QSpacerItem>
#include <QString>
37
#include <QStringList>
38
#include <QTimer>
39
40
41
42
43
44
45
#include <QWidget>
#include <QtXml>

class Atomic : public QWidget {
	Q_OBJECT

	public:
46
47
		enum PanelStyle {
			MANDATORY,
48
			DEFAULT,
49
			VALID,
50
			FAULTY
51
		};
52
		Atomic(QString section, QString key, QWidget *parent = nullptr);
53
		virtual void setDefaultPanelStyles(const QString &in_value);
Michael Reisecker's avatar
Michael Reisecker committed
54
		static QString getQtKey(const QString &ini_key);
55
		QString getIniValue(QString &section, QString &key) const noexcept;
56
		virtual void clear(const bool &set_default = true);
57
		void setHighlightedStyle(const bool &on = true, const int &reset_interval = 5000);
58
59

	protected:
60
61
		void setEmphasisWidget(QWidget *emphasis_widget, const bool &set_object_name = true);
		QWidget * getEmphasisWidget() { return emphasis_widget_; }
Michael Reisecker's avatar
Michael Reisecker committed
62
		QString getId() const noexcept { return section_ + Cst::sep + key_; }
63
		void setPanelStyle(const PanelStyle &style, const bool &set = true, QWidget *widget = nullptr);
64
		void setValidPanelStyle(const bool &on);
Michael Reisecker's avatar
Michael Reisecker committed
65
66
67
68
		void substituteKeys(QDomElement &parent_element, const QString &replace,
		    const QString &replace_with);
		QSpacerItem * buildSpacer();
		void setLayoutMargins(QLayout *layout);
69
70
		Helptext * addHelp(QHBoxLayout *layout, const QDomNode &options, const bool &tight = false,
		    const bool &force = false);
71
		void setBufferedUpdatesEnabled(const int &time = 0);
72
73
		int getElementTextWidth (const QStringList &text_list, const int &element_min_width,
		    const int &element_max_width);
74
75
		void setFontOptions(QWidget *widget, const QDomNode &options);
		QFont setFontOptions(const QFont &item_font, const QDomElement &in_options);
76

Michael Reisecker's avatar
Michael Reisecker committed
77
78
		QString section_; //INI section
		QString key_; //INI key
79
		QString ini_value_ = QString(); //the current value of the panel
80
		QWidget *emphasis_widget_ = nullptr; //widget to use for mandatory field highlighting etc.
81
82

	protected slots:
83
		virtual void onPropertySet();
84
85
86
		void setIniValue(const int &value); //called when value is set on user input or from the code
		void setIniValue(const double &value);
		void setIniValue(const QString &value);
87

Michael Reisecker's avatar
Michael Reisecker committed
88
	private:
89
90
91
		void createContextMenu();

		QMenu panel_context_menu_;
92
		INIParser *ini_ = nullptr; //pointer to the main INIParser
93
		QTimer style_timer_;
94
95
96

	private slots:
		void onTimerBufferedUpdatesEnabled();
97
		void onConextMenuRequest(const QPoint &);
98
99
100
};

#endif //ATOMIC_H