]> sigrok.org Git - pulseview.git/blame - pv/dialogs/settings.cpp
Avoid wrapping driver names etc in about box.
[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
4e4d72b2 20#include <QApplication>
bf9f1268
SA
21#include <QCheckBox>
22#include <QDialogButtonBox>
23#include <QFormLayout>
24#include <QGroupBox>
b14db788 25#include <QHBoxLayout>
4e4d72b2
SA
26#include <QLabel>
27#include <QString>
28#include <QTextBrowser>
29#include <QTextDocument>
bf9f1268
SA
30#include <QVBoxLayout>
31
4e4d72b2
SA
32#include "settings.hpp"
33
34#include "pv/devicemanager.hpp"
35#include "pv/globalsettings.hpp"
36
37#include <libsigrokcxx/libsigrokcxx.hpp>
38
39#ifdef ENABLE_DECODE
40#include <libsigrokdecode/libsigrokdecode.h>
41#endif
42
6f925ba9
UH
43using std::shared_ptr;
44
bf9f1268
SA
45namespace pv {
46namespace dialogs {
47
4e4d72b2
SA
48Settings::Settings(DeviceManager &device_manager, QWidget *parent) :
49 QDialog(parent, nullptr),
50 device_manager_(device_manager)
bf9f1268 51{
b14db788
SA
52 const int icon_size = 64;
53
4e4d72b2
SA
54 resize(600, 400);
55
b14db788
SA
56 page_list = new QListWidget;
57 page_list->setViewMode(QListView::IconMode);
58 page_list->setIconSize(QSize(icon_size, icon_size));
59 page_list->setMovement(QListView::Static);
c063290a 60 page_list->setMaximumWidth(icon_size + (icon_size / 2));
b14db788
SA
61 page_list->setSpacing(12);
62
63 pages = new QStackedWidget;
64 create_pages();
e6d42eec 65 page_list->setCurrentIndex(page_list->model()->index(0, 0));
b14db788
SA
66
67 QHBoxLayout *tab_layout = new QHBoxLayout;
68 tab_layout->addWidget(page_list);
69 tab_layout->addWidget(pages, Qt::AlignLeft);
bf9f1268
SA
70
71 QDialogButtonBox *button_box = new QDialogButtonBox(
72 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
73
74 QVBoxLayout* root_layout = new QVBoxLayout(this);
b14db788 75 root_layout->addLayout(tab_layout);
bf9f1268
SA
76 root_layout->addWidget(button_box);
77
78 connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
79 connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
b14db788
SA
80 connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
81 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
2cca9ebf
SA
82
83 // Start to record changes
84 GlobalSettings settings;
85 settings.start_tracking();
bf9f1268
SA
86}
87
b14db788
SA
88void Settings::create_pages()
89{
90 // View page
91 pages->addWidget(get_view_settings_form(pages));
92
93 QListWidgetItem *viewButton = new QListWidgetItem(page_list);
2b0aa8fd 94 viewButton->setIcon(QIcon(":/icons/settings-views.svg"));
b14db788
SA
95 viewButton->setText(tr("Views"));
96 viewButton->setTextAlignment(Qt::AlignHCenter);
97 viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
4e4d72b2
SA
98
99 // About page
100 pages->addWidget(get_about_page(pages));
101
102 QListWidgetItem *aboutButton = new QListWidgetItem(page_list);
103 aboutButton->setIcon(QIcon(":/icons/information.svg"));
104 aboutButton->setText(tr("About"));
105 aboutButton->setTextAlignment(Qt::AlignHCenter);
106 aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
b14db788
SA
107}
108
bf9f1268
SA
109QWidget *Settings::get_view_settings_form(QWidget *parent) const
110{
111 GlobalSettings settings;
112
113 QWidget *form = new QWidget(parent);
114 QVBoxLayout *form_layout = new QVBoxLayout(form);
115
116 // Trace view settings
117 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
118 form_layout->addWidget(trace_view_group);
119
120 QFormLayout *trace_view_layout = new QFormLayout();
121 trace_view_group->setLayout(trace_view_layout);
122
123 QCheckBox *coloured_bg_cb = new QCheckBox();
124 coloured_bg_cb->setChecked(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
125 connect(coloured_bg_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_colouredBG_changed(int)));
33a94f9b 126 trace_view_layout->addRow(tr("Use coloured trace &background"), coloured_bg_cb);
bf9f1268
SA
127
128 QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
129 always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
130 connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
87a97d8a
SA
131 trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during capture"), always_zoom_to_fit_cb);
132
133 QCheckBox *sticky_scrolling_cb = new QCheckBox();
134 sticky_scrolling_cb->setChecked(settings.value(GlobalSettings::Key_View_StickyScrolling).toBool());
135 connect(sticky_scrolling_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_stickyScrolling_changed(int)));
136 trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), sticky_scrolling_cb);
bf9f1268 137
051ba3b3
UH
138 QCheckBox *show_sampling_points_cb = new QCheckBox();
139 show_sampling_points_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool());
140 connect(show_sampling_points_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showSamplingPoints_changed(int)));
141 trace_view_layout->addRow(tr("Show data &sampling points"), show_sampling_points_cb);
142
8ad61f40
UH
143 QCheckBox *show_analog_minor_grid_cb = new QCheckBox();
144 show_analog_minor_grid_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool());
145 connect(show_analog_minor_grid_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showAnalogMinorGrid_changed(int)));
146 trace_view_layout->addRow(tr("Show analog minor grid in addition to vdiv grid"), show_analog_minor_grid_cb);
147
bf9f1268
SA
148 return form;
149}
150
fe934a93
GS
151#ifdef ENABLE_DECODE
152static gint sort_pds(gconstpointer a, gconstpointer b)
153{
154 const struct srd_decoder *sda, *sdb;
155
156 sda = (const struct srd_decoder *)a;
157 sdb = (const struct srd_decoder *)b;
158 return strcmp(sda->id, sdb->id);
159}
160#endif
161
4e4d72b2
SA
162QWidget *Settings::get_about_page(QWidget *parent) const
163{
164#ifdef ENABLE_DECODE
165 struct srd_decoder *dec;
166#endif
167
168 QLabel *icon = new QLabel();
169 icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/sigrok-logo-notext.svg")));
170
171 /* Setup the version field */
172 QLabel *version_info = new QLabel();
173 version_info->setText(tr("%1 %2<br />%3<br /><a href=\"http://%4\">%4</a>")
174 .arg(QApplication::applicationName(),
175 QApplication::applicationVersion(),
176 tr("GNU GPL, version 3 or later"),
177 QApplication::organizationDomain()));
178 version_info->setOpenExternalLinks(true);
179
6f925ba9 180 shared_ptr<sigrok::Context> context = device_manager_.context();
4e4d72b2
SA
181
182 QString s;
d008cab1
ML
183
184 s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
185
4e4d72b2
SA
186 s.append("<table>");
187
20c80c8a
SA
188 /* Library info */
189 s.append("<tr><td colspan=\"2\"><b>" +
213db299 190 tr("Used libraries:") + "</b></td></tr>");
20c80c8a 191 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
213db299 192 .arg(QString("Qt"), qVersion()));
6c348830
GS
193 s.append(QString("<tr><td><i>%1</i></td><td>%2 (lib version %3)</td></tr>")
194 .arg(QString("libsigrok"), sr_package_version_string_get(), sr_lib_version_string_get()));
195#ifdef ENABLE_DECODE
196 s.append(QString("<tr><td><i>%1</i></td><td>%2 (lib version %3)</td></tr>")
197 .arg(QString("libsigrokdecode"), srd_package_version_string_get(), srd_lib_version_string_get()));
198#endif
20c80c8a 199
4e4d72b2
SA
200 /* Set up the supported field */
201 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 202 tr("Supported hardware drivers:") + "</b></td></tr>");
4e4d72b2 203 for (auto entry : context->drivers()) {
d008cab1 204 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
4e4d72b2
SA
205 .arg(QString::fromUtf8(entry.first.c_str()),
206 QString::fromUtf8(entry.second->long_name().c_str())));
207 }
208
209 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 210 tr("Supported input formats:") + "</b></td></tr>");
4e4d72b2 211 for (auto entry : context->input_formats()) {
d008cab1 212 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
4e4d72b2
SA
213 .arg(QString::fromUtf8(entry.first.c_str()),
214 QString::fromUtf8(entry.second->description().c_str())));
215 }
216
217 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 218 tr("Supported output formats:") + "</b></td></tr>");
4e4d72b2 219 for (auto entry : context->output_formats()) {
d008cab1 220 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
4e4d72b2
SA
221 .arg(QString::fromUtf8(entry.first.c_str()),
222 QString::fromUtf8(entry.second->description().c_str())));
223 }
224
225#ifdef ENABLE_DECODE
226 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 227 tr("Supported protocol decoders:") + "</b></td></tr>");
fe934a93
GS
228 GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
229 sl = g_slist_sort(sl, sort_pds);
230 for (const GSList *l = sl; l; l = l->next) {
4e4d72b2 231 dec = (struct srd_decoder *)l->data;
d008cab1 232 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
4e4d72b2
SA
233 .arg(QString::fromUtf8(dec->id),
234 QString::fromUtf8(dec->longname)));
235 }
fe934a93 236 g_slist_free(sl);
4e4d72b2
SA
237#endif
238
239 s.append("</table>");
240
241 QTextDocument *supported_doc = new QTextDocument();
242 supported_doc->setHtml(s);
243
244 QTextBrowser *support_list = new QTextBrowser();
245 support_list->setDocument(supported_doc);
246
247 QGridLayout *layout = new QGridLayout();
248 layout->addWidget(icon, 0, 0, 1, 1);
249 layout->addWidget(version_info, 0, 1, 1, 1);
250 layout->addWidget(support_list, 1, 1, 1, 1);
251
252 QWidget *page = new QWidget(parent);
253 page->setLayout(layout);
254
255 return page;
256}
257
bf9f1268
SA
258void Settings::accept()
259{
2cca9ebf
SA
260 GlobalSettings settings;
261 settings.stop_tracking();
262
bf9f1268
SA
263 QDialog::accept();
264}
265
266void Settings::reject()
267{
2cca9ebf
SA
268 GlobalSettings settings;
269 settings.undo_tracked_changes();
270
bf9f1268
SA
271 QDialog::reject();
272}
273
b14db788
SA
274void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
275{
276 if (!current)
277 current = previous;
278
279 pages->setCurrentIndex(page_list->row(current));
280}
281
bf9f1268
SA
282void Settings::on_view_alwaysZoomToFit_changed(int state)
283{
284 GlobalSettings settings;
285 settings.setValue(GlobalSettings::Key_View_AlwaysZoomToFit, state ? true : false);
286}
287
288void Settings::on_view_colouredBG_changed(int state)
289{
290 GlobalSettings settings;
291 settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
292}
293
87a97d8a
SA
294void Settings::on_view_stickyScrolling_changed(int state)
295{
296 GlobalSettings settings;
297 settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
298}
299
051ba3b3
UH
300void Settings::on_view_showSamplingPoints_changed(int state)
301{
302 GlobalSettings settings;
303 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
304}
87a97d8a 305
8ad61f40
UH
306void Settings::on_view_showAnalogMinorGrid_changed(int state)
307{
308 GlobalSettings settings;
309 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
310}
311
bf9f1268
SA
312} // namespace dialogs
313} // namespace pv