]> sigrok.org Git - pulseview.git/blob - pv/dialogs/settings.cpp
eb9e88b6755ddc2813d08d66f3fd208be7f6cd21
[pulseview.git] / pv / dialogs / settings.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
5  *
6  * This program 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  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "settings.hpp"
21 #include "pv/globalsettings.hpp"
22
23 #include <QCheckBox>
24 #include <QDialogButtonBox>
25 #include <QFormLayout>
26 #include <QGroupBox>
27 #include <QTabWidget>
28 #include <QVBoxLayout>
29
30 namespace pv {
31 namespace dialogs {
32
33 Settings::Settings(QWidget *parent) :
34         QDialog(parent, nullptr)
35 {
36         QTabWidget *tab_stack = new QTabWidget(this);
37         tab_stack->addTab(get_view_settings_form(tab_stack), tr("&Views"));
38
39         QDialogButtonBox *button_box = new QDialogButtonBox(
40                 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
41
42         QVBoxLayout* root_layout = new QVBoxLayout(this);
43         root_layout->addWidget(tab_stack);
44         root_layout->addWidget(button_box);
45
46         connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
47         connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
48
49         // Start to record changes
50         GlobalSettings settings;
51         settings.start_tracking();
52 }
53
54 QWidget *Settings::get_view_settings_form(QWidget *parent) const
55 {
56         GlobalSettings settings;
57
58         QWidget *form = new QWidget(parent);
59         QVBoxLayout *form_layout = new QVBoxLayout(form);
60
61         // Trace view settings
62         QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
63         form_layout->addWidget(trace_view_group);
64
65         QFormLayout *trace_view_layout = new QFormLayout();
66         trace_view_group->setLayout(trace_view_layout);
67
68         QCheckBox *coloured_bg_cb = new QCheckBox();
69         coloured_bg_cb->setChecked(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
70         connect(coloured_bg_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_colouredBG_changed(int)));
71         trace_view_layout->addRow(tr("Use &coloured trace background"), coloured_bg_cb);
72
73         QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
74         always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
75         connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
76         trace_view_layout->addRow(tr("Always zoom-to-&fit during capture"), always_zoom_to_fit_cb);
77
78         return form;
79 }
80
81 void Settings::accept()
82 {
83         GlobalSettings settings;
84         settings.stop_tracking();
85
86         QDialog::accept();
87 }
88
89 void Settings::reject()
90 {
91         GlobalSettings settings;
92         settings.undo_tracked_changes();
93
94         QDialog::reject();
95 }
96
97 void Settings::on_view_alwaysZoomToFit_changed(int state)
98 {
99         GlobalSettings settings;
100         settings.setValue(GlobalSettings::Key_View_AlwaysZoomToFit, state ? true : false);
101 }
102
103 void Settings::on_view_colouredBG_changed(int state)
104 {
105         GlobalSettings settings;
106         settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
107 }
108
109 } // namespace dialogs
110 } // namespace pv