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>
27 #include <QHBoxLayout>
28 #include <QVBoxLayout>
33 Settings::Settings(QWidget *parent) :
34 QDialog(parent, nullptr)
36 const int icon_size = 64;
38 page_list = new QListWidget;
39 page_list->setViewMode(QListView::IconMode);
40 page_list->setIconSize(QSize(icon_size, icon_size));
41 page_list->setMovement(QListView::Static);
42 page_list->setMaximumWidth(icon_size + icon_size/2);
43 page_list->setSpacing(12);
45 pages = new QStackedWidget;
48 QHBoxLayout *tab_layout = new QHBoxLayout;
49 tab_layout->addWidget(page_list);
50 tab_layout->addWidget(pages, Qt::AlignLeft);
52 QDialogButtonBox *button_box = new QDialogButtonBox(
53 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
55 QVBoxLayout* root_layout = new QVBoxLayout(this);
56 root_layout->addLayout(tab_layout);
57 root_layout->addWidget(button_box);
59 connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
60 connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
61 connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
62 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
64 // Start to record changes
65 GlobalSettings settings;
66 settings.start_tracking();
69 void Settings::create_pages()
72 pages->addWidget(get_view_settings_form(pages));
74 QListWidgetItem *viewButton = new QListWidgetItem(page_list);
75 viewButton->setIcon(QIcon(":/icons/sigrok-logo-notext.svg"));
76 viewButton->setText(tr("Views"));
77 viewButton->setTextAlignment(Qt::AlignHCenter);
78 viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
81 QWidget *Settings::get_view_settings_form(QWidget *parent) const
83 GlobalSettings settings;
85 QWidget *form = new QWidget(parent);
86 QVBoxLayout *form_layout = new QVBoxLayout(form);
88 // Trace view settings
89 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
90 form_layout->addWidget(trace_view_group);
92 QFormLayout *trace_view_layout = new QFormLayout();
93 trace_view_group->setLayout(trace_view_layout);
95 QCheckBox *coloured_bg_cb = new QCheckBox();
96 coloured_bg_cb->setChecked(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
97 connect(coloured_bg_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_colouredBG_changed(int)));
98 trace_view_layout->addRow(tr("Use &coloured trace background"), coloured_bg_cb);
100 QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
101 always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
102 connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
103 trace_view_layout->addRow(tr("Always zoom-to-&fit during capture"), always_zoom_to_fit_cb);
108 void Settings::accept()
110 GlobalSettings settings;
111 settings.stop_tracking();
116 void Settings::reject()
118 GlobalSettings settings;
119 settings.undo_tracked_changes();
124 void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
129 pages->setCurrentIndex(page_list->row(current));
132 void Settings::on_view_alwaysZoomToFit_changed(int state)
134 GlobalSettings settings;
135 settings.setValue(GlobalSettings::Key_View_AlwaysZoomToFit, state ? true : false);
138 void Settings::on_view_colouredBG_changed(int state)
140 GlobalSettings settings;
141 settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
144 } // namespace dialogs