]> sigrok.org Git - pulseview.git/blame - pv/dialogs/settings.cpp
TraceView: Fix "always zoom to fit" feature
[pulseview.git] / pv / dialogs / settings.cpp
CommitLineData
bf9f1268
SA
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
30namespace pv {
31namespace dialogs {
32
33Settings::Settings(QWidget *parent) :
34 QDialog(parent, 0)
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
50QWidget *Settings::get_view_settings_form(QWidget *parent) const
51{
52 GlobalSettings settings;
53
54 QWidget *form = new QWidget(parent);
55 QVBoxLayout *form_layout = new QVBoxLayout(form);
56
57 // Trace view settings
58 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
59 form_layout->addWidget(trace_view_group);
60
61 QFormLayout *trace_view_layout = new QFormLayout();
62 trace_view_group->setLayout(trace_view_layout);
63
64 QCheckBox *coloured_bg_cb = new QCheckBox();
65 coloured_bg_cb->setChecked(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
66 connect(coloured_bg_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_colouredBG_changed(int)));
67 trace_view_layout->addRow(tr("Use &coloured trace background"), coloured_bg_cb);
68
69 QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
70 always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
71 connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
72 trace_view_layout->addRow(tr("Always zoom-to-&fit during capture"), always_zoom_to_fit_cb);
73
74 return form;
75}
76
77void Settings::accept()
78{
79 QDialog::accept();
80}
81
82void Settings::reject()
83{
84 QDialog::reject();
85}
86
87void Settings::on_view_alwaysZoomToFit_changed(int state)
88{
89 GlobalSettings settings;
90 settings.setValue(GlobalSettings::Key_View_AlwaysZoomToFit, state ? true : false);
91}
92
93void Settings::on_view_colouredBG_changed(int state)
94{
95 GlobalSettings settings;
96 settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
97}
98
99} // namespace dialogs
100} // namespace pv