2 * This file is part of the PulseView project.
4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
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.
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.
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/>.
20 #include "settings.hpp"
21 #include "pv/globalsettings.hpp"
24 #include <QDialogButtonBox>
25 #include <QFormLayout>
28 #include <QVBoxLayout>
33 Settings::Settings(QWidget *parent) :
34 QDialog(parent, nullptr)
36 QTabWidget *tab_stack = new QTabWidget(this);
37 tab_stack->addTab(get_view_settings_form(tab_stack), tr("&Views"));
39 QDialogButtonBox *button_box = new QDialogButtonBox(
40 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
42 QVBoxLayout* root_layout = new QVBoxLayout(this);
43 root_layout->addWidget(tab_stack);
44 root_layout->addWidget(button_box);
46 connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
47 connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
49 // Start to record changes
50 GlobalSettings settings;
51 settings.start_tracking();
54 QWidget *Settings::get_view_settings_form(QWidget *parent) const
56 GlobalSettings settings;
58 QWidget *form = new QWidget(parent);
59 QVBoxLayout *form_layout = new QVBoxLayout(form);
61 // Trace view settings
62 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
63 form_layout->addWidget(trace_view_group);
65 QFormLayout *trace_view_layout = new QFormLayout();
66 trace_view_group->setLayout(trace_view_layout);
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);
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);
81 void Settings::accept()
83 GlobalSettings settings;
84 settings.stop_tracking();
89 void Settings::reject()
91 GlobalSettings settings;
92 settings.undo_tracked_changes();
97 void Settings::on_view_alwaysZoomToFit_changed(int state)
99 GlobalSettings settings;
100 settings.setValue(GlobalSettings::Key_View_AlwaysZoomToFit, state ? true : false);
103 void Settings::on_view_colouredBG_changed(int state)
105 GlobalSettings settings;
106 settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
109 } // namespace dialogs