Fix bar displaying undecoded area
[pulseview.git] / pv / dialogs / settings.cpp
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 "config.h"
21
22 #include <glib.h>
23 #include <boost/version.hpp>
24
25 #include <QApplication>
26 #include <QComboBox>
27 #include <QDialogButtonBox>
28 #include <QFileDialog>
29 #include <QFormLayout>
30 #include <QGroupBox>
31 #include <QHBoxLayout>
32 #include <QLabel>
33 #include <QMainWindow>
34 #include <QMessageBox>
35 #include <QPushButton>
36 #include <QScrollBar>
37 #include <QSpinBox>
38 #include <QString>
39 #include <QTextBrowser>
40 #include <QTextDocument>
41 #include <QTextStream>
42 #include <QVBoxLayout>
43
44 #include "settings.hpp"
45
46 #include "pv/devicemanager.hpp"
47 #include "pv/globalsettings.hpp"
48 #include "pv/logging.hpp"
49
50 #include <libsigrokcxx/libsigrokcxx.hpp>
51
52 #ifdef ENABLE_DECODE
53 #include <libsigrokdecode/libsigrokdecode.h>
54 #endif
55
56 using std::shared_ptr;
57
58 namespace pv {
59 namespace dialogs {
60
61 /**
62  * Special version of a QListView that has the width of the first column as minimum size.
63  *
64  * @note Inspired by https://github.com/qt-creator/qt-creator/blob/master/src/plugins/coreplugin/dialogs/settingsdialog.cpp
65  */
66 class PageListWidget: public QListWidget
67 {
68 public:
69         PageListWidget() :
70                 QListWidget()
71         {
72                 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
73         }
74
75         QSize sizeHint() const final
76         {
77                 int width = sizeHintForColumn(0) + frameWidth() * 2 + 5;
78                 if (verticalScrollBar()->isVisible())
79                         width += verticalScrollBar()->width();
80                 return QSize(width, 100);
81         }
82 };
83
84 Settings::Settings(DeviceManager &device_manager, QWidget *parent) :
85         QDialog(parent, nullptr),
86         device_manager_(device_manager)
87 {
88         resize(600, 400);
89
90         // Create log view
91         log_view_ = create_log_view();
92
93         // Create pages
94         page_list = new PageListWidget();
95         page_list->setViewMode(QListView::ListMode);
96         page_list->setMovement(QListView::Static);
97         page_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
98
99         pages = new QStackedWidget;
100         create_pages();
101         page_list->setCurrentIndex(page_list->model()->index(0, 0));
102
103         // Create the rest of the dialog
104         QHBoxLayout *tab_layout = new QHBoxLayout;
105         tab_layout->addWidget(page_list);
106         tab_layout->addWidget(pages, Qt::AlignLeft);
107
108         QDialogButtonBox *button_box = new QDialogButtonBox(
109                 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
110
111         QVBoxLayout* root_layout = new QVBoxLayout(this);
112         root_layout->addLayout(tab_layout);
113         root_layout->addWidget(button_box);
114
115         connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
116         connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
117         connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
118                 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
119
120         // Start to record changes
121         GlobalSettings settings;
122         settings.start_tracking();
123 }
124
125 void Settings::create_pages()
126 {
127         // View page
128         pages->addWidget(get_view_settings_form(pages));
129
130         QListWidgetItem *viewButton = new QListWidgetItem(page_list);
131         viewButton->setIcon(QIcon(":/icons/settings-views.svg"));
132         viewButton->setText(tr("Views"));
133         viewButton->setTextAlignment(Qt::AlignVCenter);
134         viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
135
136 #ifdef ENABLE_DECODE
137         // Decoder page
138         pages->addWidget(get_decoder_settings_form(pages));
139
140         QListWidgetItem *decoderButton = new QListWidgetItem(page_list);
141         decoderButton->setIcon(QIcon(":/icons/add-decoder.svg"));
142         decoderButton->setText(tr("Decoders"));
143         decoderButton->setTextAlignment(Qt::AlignVCenter);
144         decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
145 #endif
146
147         // About page
148         pages->addWidget(get_about_page(pages));
149
150         QListWidgetItem *aboutButton = new QListWidgetItem(page_list);
151         aboutButton->setIcon(QIcon(":/icons/information.svg"));
152         aboutButton->setText(tr("About"));
153         aboutButton->setTextAlignment(Qt::AlignVCenter);
154         aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
155
156         // Logging page
157         pages->addWidget(get_logging_page(pages));
158
159         QListWidgetItem *loggingButton = new QListWidgetItem(page_list);
160         loggingButton->setIcon(QIcon(":/icons/information.svg"));
161         loggingButton->setText(tr("Logging"));
162         loggingButton->setTextAlignment(Qt::AlignVCenter);
163         loggingButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
164 }
165
166 QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const
167 {
168         GlobalSettings settings;
169
170         QCheckBox *cb = new QCheckBox();
171         cb->setChecked(settings.value(key).toBool());
172         connect(cb, SIGNAL(stateChanged(int)), this, slot);
173         return cb;
174 }
175
176 QPlainTextEdit *Settings::create_log_view() const
177 {
178         GlobalSettings settings;
179
180         QPlainTextEdit *log_view = new QPlainTextEdit();
181
182         log_view->setReadOnly(true);
183         log_view->setWordWrapMode(QTextOption::NoWrap);
184         log_view->setCenterOnScroll(true);
185
186         log_view->appendHtml(logging.get_log());
187         connect(&logging, SIGNAL(logged_text(QString)),
188                 log_view, SLOT(appendHtml(QString)));
189
190         return log_view;
191 }
192
193 QWidget *Settings::get_view_settings_form(QWidget *parent) const
194 {
195         GlobalSettings settings;
196         QCheckBox *cb;
197
198         QWidget *form = new QWidget(parent);
199         QVBoxLayout *form_layout = new QVBoxLayout(form);
200
201         // Trace view settings
202         QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
203         form_layout->addWidget(trace_view_group);
204
205         QFormLayout *trace_view_layout = new QFormLayout();
206         trace_view_group->setLayout(trace_view_layout);
207
208         cb = create_checkbox(GlobalSettings::Key_View_ColoredBG,
209                 SLOT(on_view_coloredBG_changed(int)));
210         trace_view_layout->addRow(tr("Use colored trace &background"), cb);
211
212         cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq,
213                 SLOT(on_view_zoomToFitDuringAcq_changed(int)));
214         trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb);
215
216         cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq,
217                 SLOT(on_view_zoomToFitAfterAcq_changed(int)));
218         trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb);
219
220         cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime,
221                 SLOT(on_view_triggerIsZero_changed(int)));
222         trace_view_layout->addRow(tr("Show time zero at the trigger"), cb);
223
224         cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling,
225                 SLOT(on_view_stickyScrolling_changed(int)));
226         trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb);
227
228         cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints,
229                 SLOT(on_view_showSamplingPoints_changed(int)));
230         trace_view_layout->addRow(tr("Show data &sampling points"), cb);
231
232         cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid,
233                 SLOT(on_view_showAnalogMinorGrid_changed(int)));
234         trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb);
235
236         QComboBox *thr_disp_mode_cb = new QComboBox();
237         thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
238         thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
239         thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots);
240         thr_disp_mode_cb->setCurrentIndex(
241                 settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt());
242         connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)),
243                 this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
244         trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb);
245
246         QSpinBox *default_div_height_sb = new QSpinBox();
247         default_div_height_sb->setRange(20, 1000);
248         default_div_height_sb->setSuffix(tr(" pixels"));
249         default_div_height_sb->setValue(
250                 settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt());
251         connect(default_div_height_sb, SIGNAL(valueChanged(int)), this,
252                 SLOT(on_view_defaultDivHeight_changed(int)));
253         trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb);
254
255         QSpinBox *default_logic_height_sb = new QSpinBox();
256         default_logic_height_sb->setRange(5, 1000);
257         default_logic_height_sb->setSuffix(tr(" pixels"));
258         default_logic_height_sb->setValue(
259                 settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt());
260         connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this,
261                 SLOT(on_view_defaultLogicHeight_changed(int)));
262         trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb);
263
264         return form;
265 }
266
267 QWidget *Settings::get_decoder_settings_form(QWidget *parent) const
268 {
269 #ifdef ENABLE_DECODE
270         QCheckBox *cb;
271
272         QWidget *form = new QWidget(parent);
273         QVBoxLayout *form_layout = new QVBoxLayout(form);
274
275         // Decoder settings
276         QGroupBox *decoder_group = new QGroupBox(tr("Decoders"));
277         form_layout->addWidget(decoder_group);
278
279         QFormLayout *decoder_layout = new QFormLayout();
280         decoder_group->setLayout(decoder_layout);
281
282         cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable,
283                 SLOT(on_dec_initialStateConfigurable_changed(int)));
284         decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
285
286         return form;
287 #else
288         (void)parent;
289         return nullptr;
290 #endif
291 }
292
293 #ifdef ENABLE_DECODE
294 static gint sort_pds(gconstpointer a, gconstpointer b)
295 {
296         const struct srd_decoder *sda, *sdb;
297
298         sda = (const struct srd_decoder *)a;
299         sdb = (const struct srd_decoder *)b;
300         return strcmp(sda->id, sdb->id);
301 }
302 #endif
303
304 QWidget *Settings::get_about_page(QWidget *parent) const
305 {
306 #ifdef ENABLE_DECODE
307         struct srd_decoder *dec;
308 #endif
309
310         QLabel *icon = new QLabel();
311         icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg")));
312
313         /* Setup the version field */
314         QLabel *version_info = new QLabel();
315         version_info->setText(tr("%1 %2<br />%3<br /><a href=\"http://%4\">%4</a>")
316                 .arg(QApplication::applicationName(),
317                 QApplication::applicationVersion(),
318                 tr("GNU GPL, version 3 or later"),
319                 QApplication::organizationDomain()));
320         version_info->setOpenExternalLinks(true);
321
322         shared_ptr<sigrok::Context> context = device_manager_.context();
323
324         QString s;
325
326         s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
327
328         s.append("<table>");
329
330         /* Library info */
331         s.append("<tr><td colspan=\"2\"><b>" +
332                 tr("Libraries and features:") + "</b></td></tr>");
333
334         s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
335                 .arg(QString("Qt"), qVersion()));
336         s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
337                 .arg(QString("glibmm"), PV_GLIBMM_VERSION));
338         s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
339                 .arg(QString("Boost"), BOOST_LIB_VERSION));
340
341         s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
342                 .arg(QString("libsigrok"), SR_PACKAGE_VERSION_STRING,
343                 SR_LIB_VERSION_STRING, sr_package_version_string_get(),
344                 sr_lib_version_string_get()));
345
346         GSList *l_orig = sr_buildinfo_libs_get();
347         for (GSList *l = l_orig; l; l = l->next) {
348                 GSList *m = (GSList *)l->data;
349                 const char *lib = (const char *)m->data;
350                 const char *version = (const char *)m->next->data;
351                 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
352                         .arg(QString(lib), QString(version)));
353                 g_slist_free_full(m, g_free);
354         }
355         g_slist_free(l_orig);
356
357         char *host = sr_buildinfo_host_get();
358         s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
359                 .arg(QString(host)));
360         g_free(host);
361
362         char *scpi_backends = sr_buildinfo_scpi_backends_get();
363         s.append(QString("<tr><td><i>- SCPI backends</i></td><td>%1</td></tr>")
364                 .arg(QString(scpi_backends)));
365         g_free(scpi_backends);
366
367 #ifdef ENABLE_DECODE
368         s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
369                 .arg(QString("libsigrokdecode"), SRD_PACKAGE_VERSION_STRING,
370                 SRD_LIB_VERSION_STRING, srd_package_version_string_get(),
371                 srd_lib_version_string_get()));
372
373         l_orig = srd_buildinfo_libs_get();
374         for (GSList *l = l_orig; l; l = l->next) {
375                 GSList *m = (GSList *)l->data;
376                 const char *lib = (const char *)m->data;
377                 const char *version = (const char *)m->next->data;
378                 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
379                         .arg(QString(lib), QString(version)));
380                 g_slist_free_full(m, g_free);
381         }
382         g_slist_free(l_orig);
383
384         host = srd_buildinfo_host_get();
385         s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
386                 .arg(QString(host)));
387         g_free(host);
388 #endif
389
390         s.append("<tr><td colspan=\"2\"></td></tr>");
391         s.append("<tr><td colspan=\"2\"><b>" +
392                 tr("Firmware search paths:") + "</b></td></tr>");
393
394         l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE);
395         for (GSList *l = l_orig; l; l = l->next)
396                 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(
397                         QString((char*)l->data)));
398         g_slist_free_full(l_orig, g_free);
399
400 #ifdef ENABLE_DECODE
401         s.append("<tr><td colspan=\"2\"></td></tr>");
402         s.append("<tr><td colspan=\"2\"><b>" +
403                 tr("Protocol decoder search paths:") + "</b></td></tr>");
404
405         l_orig = srd_searchpaths_get();
406         for (GSList *l = l_orig; l; l = l->next)
407                 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(
408                         QString((char*)l->data)));
409         g_slist_free_full(l_orig, g_free);
410 #endif
411
412         /* Set up the supported field */
413         s.append("<tr><td colspan=\"2\"></td></tr>");
414         s.append("<tr><td colspan=\"2\"><b>" +
415                 tr("Supported hardware drivers:") + "</b></td></tr>");
416         for (auto entry : context->drivers()) {
417                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
418                         .arg(QString::fromUtf8(entry.first.c_str()),
419                                 QString::fromUtf8(entry.second->long_name().c_str())));
420         }
421
422         s.append("<tr><td colspan=\"2\"></td></tr>");
423         s.append("<tr><td colspan=\"2\"><b>" +
424                 tr("Supported input formats:") + "</b></td></tr>");
425         for (auto entry : context->input_formats()) {
426                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
427                         .arg(QString::fromUtf8(entry.first.c_str()),
428                                 QString::fromUtf8(entry.second->description().c_str())));
429         }
430
431         s.append("<tr><td colspan=\"2\"></td></tr>");
432         s.append("<tr><td colspan=\"2\"><b>" +
433                 tr("Supported output formats:") + "</b></td></tr>");
434         for (auto entry : context->output_formats()) {
435                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
436                         .arg(QString::fromUtf8(entry.first.c_str()),
437                                 QString::fromUtf8(entry.second->description().c_str())));
438         }
439
440 #ifdef ENABLE_DECODE
441         s.append("<tr><td colspan=\"2\"></td></tr>");
442         s.append("<tr><td colspan=\"2\"><b>" +
443                 tr("Supported protocol decoders:") + "</b></td></tr>");
444         GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
445         sl = g_slist_sort(sl, sort_pds);
446         for (const GSList *l = sl; l; l = l->next) {
447                 dec = (struct srd_decoder *)l->data;
448                 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
449                         .arg(QString::fromUtf8(dec->id),
450                                 QString::fromUtf8(dec->longname)));
451         }
452         g_slist_free(sl);
453 #endif
454
455         s.append("</table>");
456
457         QTextDocument *supported_doc = new QTextDocument();
458         supported_doc->setHtml(s);
459
460         QTextBrowser *support_list = new QTextBrowser();
461         support_list->setDocument(supported_doc);
462
463         QGridLayout *layout = new QGridLayout();
464         layout->addWidget(icon, 0, 0, 1, 1);
465         layout->addWidget(version_info, 0, 1, 1, 1);
466         layout->addWidget(support_list, 1, 1, 1, 1);
467
468         QWidget *page = new QWidget(parent);
469         page->setLayout(layout);
470
471         return page;
472 }
473
474 QWidget *Settings::get_logging_page(QWidget *parent) const
475 {
476         GlobalSettings settings;
477
478         // Log level
479         QSpinBox *loglevel_sb = new QSpinBox();
480         loglevel_sb->setMaximum(SR_LOG_SPEW);
481         loglevel_sb->setValue(logging.get_log_level());
482         connect(loglevel_sb, SIGNAL(valueChanged(int)), this,
483                 SLOT(on_log_logLevel_changed(int)));
484
485         QHBoxLayout *loglevel_layout = new QHBoxLayout();
486         loglevel_layout->addWidget(new QLabel(tr("Log level:")));
487         loglevel_layout->addWidget(loglevel_sb);
488
489         // Background buffer size
490         QSpinBox *buffersize_sb = new QSpinBox();
491         buffersize_sb->setSuffix(tr(" lines"));
492         buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE);
493         buffersize_sb->setValue(
494                 settings.value(GlobalSettings::Key_Log_BufferSize).toInt());
495         connect(buffersize_sb, SIGNAL(valueChanged(int)), this,
496                 SLOT(on_log_bufferSize_changed(int)));
497
498         QHBoxLayout *buffersize_layout = new QHBoxLayout();
499         buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:")));
500         buffersize_layout->addWidget(buffersize_sb);
501
502         // Save to file
503         QPushButton *save_log_pb = new QPushButton(
504                 QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")),
505                 tr("&Save to File"));
506         connect(save_log_pb, SIGNAL(clicked(bool)),
507                 this, SLOT(on_log_saveToFile_clicked(bool)));
508
509         // Pop out
510         QPushButton *pop_out_pb = new QPushButton(
511                 QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")),
512                 tr("&Pop out"));
513         connect(pop_out_pb, SIGNAL(clicked(bool)),
514                 this, SLOT(on_log_popOut_clicked(bool)));
515
516         QHBoxLayout *control_layout = new QHBoxLayout();
517         control_layout->addLayout(loglevel_layout);
518         control_layout->addLayout(buffersize_layout);
519         control_layout->addWidget(save_log_pb);
520         control_layout->addWidget(pop_out_pb);
521
522         QVBoxLayout *root_layout = new QVBoxLayout();
523         root_layout->addLayout(control_layout);
524         root_layout->addWidget(log_view_);
525
526         QWidget *page = new QWidget(parent);
527         page->setLayout(root_layout);
528
529         return page;
530 }
531
532 void Settings::accept()
533 {
534         GlobalSettings settings;
535         settings.stop_tracking();
536
537         QDialog::accept();
538 }
539
540 void Settings::reject()
541 {
542         GlobalSettings settings;
543         settings.undo_tracked_changes();
544
545         QDialog::reject();
546 }
547
548 void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
549 {
550         if (!current)
551                 current = previous;
552
553         pages->setCurrentIndex(page_list->row(current));
554 }
555
556 void Settings::on_view_zoomToFitDuringAcq_changed(int state)
557 {
558         GlobalSettings settings;
559         settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false);
560 }
561
562 void Settings::on_view_zoomToFitAfterAcq_changed(int state)
563 {
564         GlobalSettings settings;
565         settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false);
566 }
567
568 void Settings::on_view_triggerIsZero_changed(int state)
569 {
570         GlobalSettings settings;
571         settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false);
572 }
573
574 void Settings::on_view_coloredBG_changed(int state)
575 {
576         GlobalSettings settings;
577         settings.setValue(GlobalSettings::Key_View_ColoredBG, state ? true : false);
578 }
579
580 void Settings::on_view_stickyScrolling_changed(int state)
581 {
582         GlobalSettings settings;
583         settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
584 }
585
586 void Settings::on_view_showSamplingPoints_changed(int state)
587 {
588         GlobalSettings settings;
589         settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
590 }
591
592 void Settings::on_view_showAnalogMinorGrid_changed(int state)
593 {
594         GlobalSettings settings;
595         settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
596 }
597
598 void Settings::on_view_conversionThresholdDispMode_changed(int state)
599 {
600         GlobalSettings settings;
601         settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state);
602 }
603
604 void Settings::on_view_defaultDivHeight_changed(int value)
605 {
606         GlobalSettings settings;
607         settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value);
608 }
609
610 void Settings::on_view_defaultLogicHeight_changed(int value)
611 {
612         GlobalSettings settings;
613         settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value);
614 }
615
616 void Settings::on_dec_initialStateConfigurable_changed(int state)
617 {
618         GlobalSettings settings;
619         settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
620 }
621
622 void Settings::on_log_logLevel_changed(int value)
623 {
624         logging.set_log_level(value);
625 }
626
627 void Settings::on_log_bufferSize_changed(int value)
628 {
629         GlobalSettings settings;
630         settings.setValue(GlobalSettings::Key_Log_BufferSize, value);
631 }
632
633 void Settings::on_log_saveToFile_clicked(bool checked)
634 {
635         (void)checked;
636
637         const QString file_name = QFileDialog::getSaveFileName(
638                 this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)"));
639
640         if (file_name.isEmpty())
641                 return;
642
643         QFile file(file_name);
644         if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
645                 QTextStream out_stream(&file);
646                 out_stream << log_view_->toPlainText();
647
648                 if (out_stream.status() == QTextStream::Ok) {
649                         QMessageBox msg(this);
650                         msg.setText(tr("Success"));
651                         msg.setInformativeText(tr("Log saved to %1.").arg(file_name));
652                         msg.setStandardButtons(QMessageBox::Ok);
653                         msg.setIcon(QMessageBox::Information);
654                         msg.exec();
655
656                         return;
657                 }
658         }
659
660         QMessageBox msg(this);
661         msg.setText(tr("Error"));
662         msg.setInformativeText(tr("File %1 could not be written to.").arg(file_name));
663         msg.setStandardButtons(QMessageBox::Ok);
664         msg.setIcon(QMessageBox::Warning);
665         msg.exec();
666 }
667
668 void Settings::on_log_popOut_clicked(bool checked)
669 {
670         (void)checked;
671
672         // Create the window as a sub-window so it closes when the main window closes
673         QMainWindow *window = new QMainWindow(nullptr, Qt::SubWindow);
674
675         window->setObjectName(QString::fromUtf8("Log Window"));
676         window->setWindowTitle(tr("%1 Log").arg(PV_TITLE));
677
678         // Use same width/height as the settings dialog
679         window->resize(width(), height());
680
681         window->setCentralWidget(create_log_view());
682         window->show();
683 }
684
685 } // namespace dialogs
686 } // namespace pv