File: globalsettings.hpp

package info (click to toggle)
pulseview 0.4.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,092 kB
  • sloc: cpp: 25,958; xml: 215; java: 42; makefile: 2
file content (149 lines) | stat: -rw-r--r-- 4,378 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * This file is part of the PulseView project.
 *
 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef PULSEVIEW_GLOBALSETTINGS_HPP
#define PULSEVIEW_GLOBALSETTINGS_HPP

#include <map>

#include <glib.h>
#include <glibmm/variant.h>

#include <QPalette>
#include <QSettings>
#include <QString>
#include <QVariant>

#include "util.hpp"

using std::map;
using std::pair;
using std::vector;

namespace pv {

extern const vector< pair<QString, QString> > Themes;


class GlobalSettingsInterface
{
public:
	virtual void on_setting_changed(const QString &key, const QVariant &value) = 0;
};


class GlobalSettings : public QSettings
{
	Q_OBJECT

public:
	static const QString Key_General_Language;
	static const QString Key_General_Theme;
	static const QString Key_General_Style;
	static const QString Key_General_SaveWithSetup;
	static const QString Key_View_ZoomToFitDuringAcq;
	static const QString Key_View_ZoomToFitAfterAcq;
	static const QString Key_View_TriggerIsZeroTime;
	static const QString Key_View_ColoredBG;
	static const QString Key_View_StickyScrolling;
	static const QString Key_View_ShowSamplingPoints;
	static const QString Key_View_FillSignalHighAreas;
	static const QString Key_View_FillSignalHighAreaColor;
	static const QString Key_View_ShowAnalogMinorGrid;
	static const QString Key_View_ConversionThresholdDispMode;
	static const QString Key_View_DefaultDivHeight;
	static const QString Key_View_DefaultLogicHeight;
	static const QString Key_View_ShowHoverMarker;
	static const QString Key_View_SnapDistance;
	static const QString Key_View_CursorFillColor;
	static const QString Key_View_CursorShowInterval;
	static const QString Key_View_CursorShowFrequency;
	static const QString Key_View_CursorShowSamples;
	static const QString Key_Dec_InitialStateConfigurable;
	static const QString Key_Dec_ExportFormat;
	static const QString Key_Dec_AlwaysShowAllRows;
	static const QString Key_Log_BufferSize;
	static const QString Key_Log_NotifyOfStacktrace;

	enum ConvThrDispMode {
		ConvThrDispMode_None = 0,
		ConvThrDispMode_Background,
		ConvThrDispMode_Dots
	};

public:
	GlobalSettings();

	void save_internal_defaults();
	void set_defaults_where_needed();
	void set_bright_theme_default_colors();
	void set_dark_theme_default_colors();

	static bool current_theme_is_dark();
	void apply_theme();

	void apply_language();

	static void add_change_handler(GlobalSettingsInterface *cb);
	static void remove_change_handler(GlobalSettingsInterface *cb);

	void setValue(const QString& key, const QVariant& value);

	/**
	 * Begins the tracking of changes. All changes will
	 * be recorded until stop_tracking() is called.
	 * The change tracking is global and doesn't support nesting.
	 */
	void start_tracking();

	/**
	 * Ends the tracking of changes without any changes to the settings.
	 */
	void stop_tracking();

	/**
	 * Ends the tracking of changes, undoing the changes since the
	 * change tracking began.
	 */
	void undo_tracked_changes();

	static void store_gvariant(QSettings &settings, GVariant *v);
	static GVariant* restore_gvariant(QSettings &settings);

	static void store_variantbase(QSettings &settings, Glib::VariantBase v);
	static Glib::VariantBase restore_variantbase(QSettings &settings);

	static void store_timestamp(QSettings &settings, const char *name, const pv::util::Timestamp &ts);
	static pv::util::Timestamp restore_timestamp(QSettings &settings, const char *name);

private:
	static vector<GlobalSettingsInterface*> callbacks_;

	static bool tracking_;
	static map<QString, QVariant> tracked_changes_;

	static QString default_style_;
	static QPalette default_palette_;

	static bool is_dark_theme_;
};

} // namespace pv

#endif // PULSEVIEW_GLOBALSETTINGS_HPP