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