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/>.
23 #include <boost/version.hpp>
25 #include <QApplication>
27 #include <QDialogButtonBox>
28 #include <QFormLayout>
30 #include <QHBoxLayout>
34 #include <QTextBrowser>
35 #include <QTextDocument>
36 #include <QVBoxLayout>
38 #include "settings.hpp"
40 #include "pv/devicemanager.hpp"
41 #include "pv/globalsettings.hpp"
43 #include <libsigrokcxx/libsigrokcxx.hpp>
46 #include <libsigrokdecode/libsigrokdecode.h>
49 using std::shared_ptr;
54 Settings::Settings(DeviceManager &device_manager, QWidget *parent) :
55 QDialog(parent, nullptr),
56 device_manager_(device_manager)
58 const int icon_size = 64;
62 page_list = new QListWidget;
63 page_list->setViewMode(QListView::IconMode);
64 page_list->setIconSize(QSize(icon_size, icon_size));
65 page_list->setMovement(QListView::Static);
66 page_list->setMaximumWidth(icon_size + (icon_size / 2));
67 page_list->setSpacing(12);
69 pages = new QStackedWidget;
71 page_list->setCurrentIndex(page_list->model()->index(0, 0));
73 QHBoxLayout *tab_layout = new QHBoxLayout;
74 tab_layout->addWidget(page_list);
75 tab_layout->addWidget(pages, Qt::AlignLeft);
77 QDialogButtonBox *button_box = new QDialogButtonBox(
78 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
80 QVBoxLayout* root_layout = new QVBoxLayout(this);
81 root_layout->addLayout(tab_layout);
82 root_layout->addWidget(button_box);
84 connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
85 connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
86 connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
87 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
89 // Start to record changes
90 GlobalSettings settings;
91 settings.start_tracking();
94 void Settings::create_pages()
97 pages->addWidget(get_view_settings_form(pages));
99 QListWidgetItem *viewButton = new QListWidgetItem(page_list);
100 viewButton->setIcon(QIcon(":/icons/settings-views.svg"));
101 viewButton->setText(tr("Views"));
102 viewButton->setTextAlignment(Qt::AlignHCenter);
103 viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
107 pages->addWidget(get_decoder_settings_form(pages));
109 QListWidgetItem *decoderButton = new QListWidgetItem(page_list);
110 decoderButton->setIcon(QIcon(":/icons/add-decoder.svg"));
111 decoderButton->setText(tr("Decoders"));
112 decoderButton->setTextAlignment(Qt::AlignHCenter);
113 decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
117 pages->addWidget(get_about_page(pages));
119 QListWidgetItem *aboutButton = new QListWidgetItem(page_list);
120 aboutButton->setIcon(QIcon(":/icons/information.svg"));
121 aboutButton->setText(tr("About"));
122 aboutButton->setTextAlignment(Qt::AlignHCenter);
123 aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
126 QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const
128 GlobalSettings settings;
130 QCheckBox *cb = new QCheckBox();
131 cb->setChecked(settings.value(key).toBool());
132 connect(cb, SIGNAL(stateChanged(int)), this, slot);
136 QWidget *Settings::get_view_settings_form(QWidget *parent) const
138 GlobalSettings settings;
141 QWidget *form = new QWidget(parent);
142 QVBoxLayout *form_layout = new QVBoxLayout(form);
144 // Trace view settings
145 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
146 form_layout->addWidget(trace_view_group);
148 QFormLayout *trace_view_layout = new QFormLayout();
149 trace_view_group->setLayout(trace_view_layout);
151 cb = create_checkbox(GlobalSettings::Key_View_ColouredBG,
152 SLOT(on_view_colouredBG_changed(int)));
153 trace_view_layout->addRow(tr("Use coloured trace &background"), cb);
155 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq,
156 SLOT(on_view_zoomToFitDuringAcq_changed(int)));
157 trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb);
159 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq,
160 SLOT(on_view_zoomToFitAfterAcq_changed(int)));
161 trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb);
163 cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling,
164 SLOT(on_view_stickyScrolling_changed(int)));
165 trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb);
167 cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints,
168 SLOT(on_view_showSamplingPoints_changed(int)));
169 trace_view_layout->addRow(tr("Show data &sampling points"), cb);
171 cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid,
172 SLOT(on_view_showAnalogMinorGrid_changed(int)));
173 trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb);
175 QComboBox *thr_disp_mode_cb = new QComboBox();
176 thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
177 thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
178 thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots);
179 thr_disp_mode_cb->setCurrentIndex(
180 settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt());
181 connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)),
182 this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
183 trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb);
185 QSpinBox *default_div_height_sb = new QSpinBox();
186 default_div_height_sb->setRange(20, 1000);
187 default_div_height_sb->setSuffix(tr(" pixels"));
188 default_div_height_sb->setValue(
189 settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt());
190 connect(default_div_height_sb, SIGNAL(valueChanged(int)), this,
191 SLOT(on_view_defaultDivHeight_changed(int)));
192 trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb);
194 QSpinBox *default_logic_height_sb = new QSpinBox();
195 default_logic_height_sb->setRange(5, 1000);
196 default_logic_height_sb->setSuffix(tr(" pixels"));
197 default_logic_height_sb->setValue(
198 settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt());
199 connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this,
200 SLOT(on_view_defaultLogicHeight_changed(int)));
201 trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb);
206 QWidget *Settings::get_decoder_settings_form(QWidget *parent) const
211 QWidget *form = new QWidget(parent);
212 QVBoxLayout *form_layout = new QVBoxLayout(form);
215 QGroupBox *decoder_group = new QGroupBox(tr("Decoders"));
216 form_layout->addWidget(decoder_group);
218 QFormLayout *decoder_layout = new QFormLayout();
219 decoder_group->setLayout(decoder_layout);
221 cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable,
222 SLOT(on_dec_initialStateConfigurable_changed(int)));
223 decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
233 static gint sort_pds(gconstpointer a, gconstpointer b)
235 const struct srd_decoder *sda, *sdb;
237 sda = (const struct srd_decoder *)a;
238 sdb = (const struct srd_decoder *)b;
239 return strcmp(sda->id, sdb->id);
243 QWidget *Settings::get_about_page(QWidget *parent) const
246 struct srd_decoder *dec;
249 QLabel *icon = new QLabel();
250 icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg")));
252 /* Setup the version field */
253 QLabel *version_info = new QLabel();
254 version_info->setText(tr("%1 %2<br />%3<br /><a href=\"http://%4\">%4</a>")
255 .arg(QApplication::applicationName(),
256 QApplication::applicationVersion(),
257 tr("GNU GPL, version 3 or later"),
258 QApplication::organizationDomain()));
259 version_info->setOpenExternalLinks(true);
261 shared_ptr<sigrok::Context> context = device_manager_.context();
265 s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
270 s.append("<tr><td colspan=\"2\"><b>" +
271 tr("Libraries and features:") + "</b></td></tr>");
273 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
274 .arg(QString("Qt"), qVersion()));
275 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
276 .arg(QString("glibmm"), PV_GLIBMM_VERSION));
277 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
278 .arg(QString("Boost"), BOOST_LIB_VERSION));
280 s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
281 .arg(QString("libsigrok"), SR_PACKAGE_VERSION_STRING,
282 SR_LIB_VERSION_STRING, sr_package_version_string_get(),
283 sr_lib_version_string_get()));
285 GSList *l_orig = sr_buildinfo_libs_get();
286 for (GSList *l = l_orig; l; l = l->next) {
287 GSList *m = (GSList *)l->data;
288 const char *lib = (const char *)m->data;
289 const char *version = (const char *)m->next->data;
290 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
291 .arg(QString(lib), QString(version)));
292 g_slist_free_full(m, g_free);
294 g_slist_free(l_orig);
296 char *host = sr_buildinfo_host_get();
297 s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
298 .arg(QString(host)));
301 char *scpi_backends = sr_buildinfo_scpi_backends_get();
302 s.append(QString("<tr><td><i>- SCPI backends</i></td><td>%1</td></tr>")
303 .arg(QString(scpi_backends)));
304 g_free(scpi_backends);
307 s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
308 .arg(QString("libsigrokdecode"), SRD_PACKAGE_VERSION_STRING,
309 SRD_LIB_VERSION_STRING, srd_package_version_string_get(),
310 srd_lib_version_string_get()));
312 l_orig = srd_buildinfo_libs_get();
313 for (GSList *l = l_orig; l; l = l->next) {
314 GSList *m = (GSList *)l->data;
315 const char *lib = (const char *)m->data;
316 const char *version = (const char *)m->next->data;
317 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
318 .arg(QString(lib), QString(version)));
319 g_slist_free_full(m, g_free);
321 g_slist_free(l_orig);
323 host = srd_buildinfo_host_get();
324 s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
325 .arg(QString(host)));
329 /* Set up the supported field */
330 s.append("<tr><td colspan=\"2\"></td></tr>");
331 s.append("<tr><td colspan=\"2\"><b>" +
332 tr("Supported hardware drivers:") + "</b></td></tr>");
333 for (auto entry : context->drivers()) {
334 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
335 .arg(QString::fromUtf8(entry.first.c_str()),
336 QString::fromUtf8(entry.second->long_name().c_str())));
339 s.append("<tr><td colspan=\"2\"></td></tr>");
340 s.append("<tr><td colspan=\"2\"><b>" +
341 tr("Supported input formats:") + "</b></td></tr>");
342 for (auto entry : context->input_formats()) {
343 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
344 .arg(QString::fromUtf8(entry.first.c_str()),
345 QString::fromUtf8(entry.second->description().c_str())));
348 s.append("<tr><td colspan=\"2\"></td></tr>");
349 s.append("<tr><td colspan=\"2\"><b>" +
350 tr("Supported output formats:") + "</b></td></tr>");
351 for (auto entry : context->output_formats()) {
352 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
353 .arg(QString::fromUtf8(entry.first.c_str()),
354 QString::fromUtf8(entry.second->description().c_str())));
358 s.append("<tr><td colspan=\"2\"></td></tr>");
359 s.append("<tr><td colspan=\"2\"><b>" +
360 tr("Supported protocol decoders:") + "</b></td></tr>");
361 GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
362 sl = g_slist_sort(sl, sort_pds);
363 for (const GSList *l = sl; l; l = l->next) {
364 dec = (struct srd_decoder *)l->data;
365 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
366 .arg(QString::fromUtf8(dec->id),
367 QString::fromUtf8(dec->longname)));
372 s.append("</table>");
374 QTextDocument *supported_doc = new QTextDocument();
375 supported_doc->setHtml(s);
377 QTextBrowser *support_list = new QTextBrowser();
378 support_list->setDocument(supported_doc);
380 QGridLayout *layout = new QGridLayout();
381 layout->addWidget(icon, 0, 0, 1, 1);
382 layout->addWidget(version_info, 0, 1, 1, 1);
383 layout->addWidget(support_list, 1, 1, 1, 1);
385 QWidget *page = new QWidget(parent);
386 page->setLayout(layout);
391 void Settings::accept()
393 GlobalSettings settings;
394 settings.stop_tracking();
399 void Settings::reject()
401 GlobalSettings settings;
402 settings.undo_tracked_changes();
407 void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
412 pages->setCurrentIndex(page_list->row(current));
415 void Settings::on_view_zoomToFitDuringAcq_changed(int state)
417 GlobalSettings settings;
418 settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false);
421 void Settings::on_view_zoomToFitAfterAcq_changed(int state)
423 GlobalSettings settings;
424 settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false);
427 void Settings::on_view_colouredBG_changed(int state)
429 GlobalSettings settings;
430 settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
433 void Settings::on_view_stickyScrolling_changed(int state)
435 GlobalSettings settings;
436 settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
439 void Settings::on_view_showSamplingPoints_changed(int state)
441 GlobalSettings settings;
442 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
445 void Settings::on_view_showAnalogMinorGrid_changed(int state)
447 GlobalSettings settings;
448 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
451 void Settings::on_view_conversionThresholdDispMode_changed(int state)
453 GlobalSettings settings;
454 settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state);
457 void Settings::on_view_defaultDivHeight_changed(int value)
459 GlobalSettings settings;
460 settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value);
463 void Settings::on_view_defaultLogicHeight_changed(int value)
465 GlobalSettings settings;
466 settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value);
469 void Settings::on_dec_initialStateConfigurable_changed(int state)
471 GlobalSettings settings;
472 settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
475 } // namespace dialogs