]> sigrok.org Git - pulseview.git/blame - pv/dialogs/settings.cpp
Ask user about adjusting UI colors when choosing a theme
[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
UH
22#include <glib.h>
23
4e4d72b2 24#include <QApplication>
90ee1ed9 25#include <QComboBox>
bf9f1268 26#include <QDialogButtonBox>
bcb4c327 27#include <QFileDialog>
bf9f1268
SA
28#include <QFormLayout>
29#include <QGroupBox>
b14db788 30#include <QHBoxLayout>
4e4d72b2 31#include <QLabel>
bcb4c327
SA
32#include <QMainWindow>
33#include <QMessageBox>
34#include <QPushButton>
03443f37 35#include <QScrollBar>
daa54986 36#include <QSpinBox>
4e4d72b2 37#include <QString>
374c697f 38#include <QStyleFactory>
4e4d72b2
SA
39#include <QTextBrowser>
40#include <QTextDocument>
bcb4c327 41#include <QTextStream>
bf9f1268
SA
42#include <QVBoxLayout>
43
4e4d72b2
SA
44#include "settings.hpp"
45
49719858 46#include "pv/application.hpp"
4e4d72b2
SA
47#include "pv/devicemanager.hpp"
48#include "pv/globalsettings.hpp"
bcb4c327 49#include "pv/logging.hpp"
4521022b 50#include "pv/widgets/colorbutton.hpp"
4e4d72b2
SA
51
52#include <libsigrokcxx/libsigrokcxx.hpp>
53
54#ifdef ENABLE_DECODE
55#include <libsigrokdecode/libsigrokdecode.h>
56#endif
57
4521022b 58using pv::widgets::ColorButton;
6f925ba9 59
bf9f1268
SA
60namespace pv {
61namespace dialogs {
62
03443f37
SA
63/**
64 * Special version of a QListView that has the width of the first column as minimum size.
65 *
66 * @note Inspired by https://github.com/qt-creator/qt-creator/blob/master/src/plugins/coreplugin/dialogs/settingsdialog.cpp
67 */
68class PageListWidget: public QListWidget
69{
70public:
71 PageListWidget() :
72 QListWidget()
73 {
74 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
75 }
76
77 QSize sizeHint() const final
78 {
79 int width = sizeHintForColumn(0) + frameWidth() * 2 + 5;
80 if (verticalScrollBar()->isVisible())
81 width += verticalScrollBar()->width();
82 return QSize(width, 100);
83 }
84};
85
4e4d72b2
SA
86Settings::Settings(DeviceManager &device_manager, QWidget *parent) :
87 QDialog(parent, nullptr),
88 device_manager_(device_manager)
bf9f1268 89{
4e4d72b2
SA
90 resize(600, 400);
91
bcb4c327
SA
92 // Create log view
93 log_view_ = create_log_view();
94
95 // Create pages
03443f37
SA
96 page_list = new PageListWidget();
97 page_list->setViewMode(QListView::ListMode);
b14db788 98 page_list->setMovement(QListView::Static);
03443f37 99 page_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
b14db788
SA
100
101 pages = new QStackedWidget;
102 create_pages();
e6d42eec 103 page_list->setCurrentIndex(page_list->model()->index(0, 0));
b14db788 104
03443f37 105 // Create the rest of the dialog
b14db788
SA
106 QHBoxLayout *tab_layout = new QHBoxLayout;
107 tab_layout->addWidget(page_list);
108 tab_layout->addWidget(pages, Qt::AlignLeft);
bf9f1268
SA
109
110 QDialogButtonBox *button_box = new QDialogButtonBox(
111 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
112
113 QVBoxLayout* root_layout = new QVBoxLayout(this);
b14db788 114 root_layout->addLayout(tab_layout);
bf9f1268
SA
115 root_layout->addWidget(button_box);
116
117 connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
118 connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
b14db788
SA
119 connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
120 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
2cca9ebf
SA
121
122 // Start to record changes
123 GlobalSettings settings;
124 settings.start_tracking();
bf9f1268
SA
125}
126
b14db788
SA
127void Settings::create_pages()
128{
37b0bd35
SA
129 // General page
130 pages->addWidget(get_general_settings_form(pages));
131
132 QListWidgetItem *generalButton = new QListWidgetItem(page_list);
133 generalButton->setIcon(QIcon(":/icons/settings-general.png"));
134 generalButton->setText(tr("General"));
135 generalButton->setTextAlignment(Qt::AlignVCenter);
136 generalButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
137
b14db788
SA
138 // View page
139 pages->addWidget(get_view_settings_form(pages));
140
141 QListWidgetItem *viewButton = new QListWidgetItem(page_list);
2b0aa8fd 142 viewButton->setIcon(QIcon(":/icons/settings-views.svg"));
b14db788 143 viewButton->setText(tr("Views"));
03443f37 144 viewButton->setTextAlignment(Qt::AlignVCenter);
b14db788 145 viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
4e4d72b2 146
669686c1
SA
147#ifdef ENABLE_DECODE
148 // Decoder page
149 pages->addWidget(get_decoder_settings_form(pages));
150
151 QListWidgetItem *decoderButton = new QListWidgetItem(page_list);
152 decoderButton->setIcon(QIcon(":/icons/add-decoder.svg"));
153 decoderButton->setText(tr("Decoders"));
03443f37 154 decoderButton->setTextAlignment(Qt::AlignVCenter);
669686c1
SA
155 decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
156#endif
157
4e4d72b2
SA
158 // About page
159 pages->addWidget(get_about_page(pages));
160
161 QListWidgetItem *aboutButton = new QListWidgetItem(page_list);
162 aboutButton->setIcon(QIcon(":/icons/information.svg"));
163 aboutButton->setText(tr("About"));
03443f37 164 aboutButton->setTextAlignment(Qt::AlignVCenter);
4e4d72b2 165 aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
bcb4c327
SA
166
167 // Logging page
168 pages->addWidget(get_logging_page(pages));
169
170 QListWidgetItem *loggingButton = new QListWidgetItem(page_list);
171 loggingButton->setIcon(QIcon(":/icons/information.svg"));
172 loggingButton->setText(tr("Logging"));
03443f37 173 loggingButton->setTextAlignment(Qt::AlignVCenter);
bcb4c327 174 loggingButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
b14db788
SA
175}
176
72df22b8 177QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const
bf9f1268
SA
178{
179 GlobalSettings settings;
180
72df22b8
SA
181 QCheckBox *cb = new QCheckBox();
182 cb->setChecked(settings.value(key).toBool());
183 connect(cb, SIGNAL(stateChanged(int)), this, slot);
184 return cb;
185}
186
bcb4c327
SA
187QPlainTextEdit *Settings::create_log_view() const
188{
189 GlobalSettings settings;
190
191 QPlainTextEdit *log_view = new QPlainTextEdit();
192
193 log_view->setReadOnly(true);
194 log_view->setWordWrapMode(QTextOption::NoWrap);
195 log_view->setCenterOnScroll(true);
196
197 log_view->appendHtml(logging.get_log());
198 connect(&logging, SIGNAL(logged_text(QString)),
199 log_view, SLOT(appendHtml(QString)));
200
201 return log_view;
202}
203
37b0bd35
SA
204QWidget *Settings::get_general_settings_form(QWidget *parent) const
205{
206 GlobalSettings settings;
207
208 QWidget *form = new QWidget(parent);
209 QVBoxLayout *form_layout = new QVBoxLayout(form);
210
211 // General settings
212 QGroupBox *general_group = new QGroupBox(tr("General"));
213 form_layout->addWidget(general_group);
214
215 QFormLayout *general_layout = new QFormLayout();
216 general_group->setLayout(general_layout);
217
218 QComboBox *theme_cb = new QComboBox();
f4ab4b5c 219 for (const pair<QString, QString>& entry : Themes)
37b0bd35
SA
220 theme_cb->addItem(entry.first, entry.second);
221
222 theme_cb->setCurrentIndex(
223 settings.value(GlobalSettings::Key_General_Theme).toInt());
224 connect(theme_cb, SIGNAL(currentIndexChanged(int)),
225 this, SLOT(on_general_theme_changed_changed(int)));
226 general_layout->addRow(tr("User interface theme"), theme_cb);
227
228 QLabel *description_1 = new QLabel(tr("(You may need to restart PulseView for all UI elements to update)"));
229 description_1->setAlignment(Qt::AlignRight);
230 general_layout->addRow(description_1);
231
374c697f
SA
232 QComboBox *style_cb = new QComboBox();
233 style_cb->addItem(tr("System Default"), "");
234 for (QString& s : QStyleFactory::keys())
235 style_cb->addItem(s, s);
236
237 const QString current_style =
238 settings.value(GlobalSettings::Key_General_Style).toString();
239 if (current_style.isEmpty())
240 style_cb->setCurrentIndex(0);
241 else
242 style_cb->setCurrentIndex(style_cb->findText(current_style, 0));
243
244 connect(style_cb, SIGNAL(currentIndexChanged(int)),
245 this, SLOT(on_general_style_changed(int)));
246 general_layout->addRow(tr("Qt widget style"), style_cb);
247
248 QLabel *description_2 = new QLabel(tr("(Dark themes look best with the Fusion style)"));
249 description_2->setAlignment(Qt::AlignRight);
250 general_layout->addRow(description_2);
251
37b0bd35
SA
252 return form;
253}
254
72df22b8
SA
255QWidget *Settings::get_view_settings_form(QWidget *parent) const
256{
daa54986 257 GlobalSettings settings;
72df22b8
SA
258 QCheckBox *cb;
259
bf9f1268
SA
260 QWidget *form = new QWidget(parent);
261 QVBoxLayout *form_layout = new QVBoxLayout(form);
262
263 // Trace view settings
264 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
265 form_layout->addWidget(trace_view_group);
266
267 QFormLayout *trace_view_layout = new QFormLayout();
268 trace_view_group->setLayout(trace_view_layout);
269
641574bc
SA
270 cb = create_checkbox(GlobalSettings::Key_View_ColoredBG,
271 SLOT(on_view_coloredBG_changed(int)));
272 trace_view_layout->addRow(tr("Use colored trace &background"), cb);
bf9f1268 273
e91fb166
SA
274 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq,
275 SLOT(on_view_zoomToFitDuringAcq_changed(int)));
276 trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb);
87a97d8a 277
28ceff25
SA
278 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq,
279 SLOT(on_view_zoomToFitAfterAcq_changed(int)));
280 trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb);
281
ffc00fdd
C
282 cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime,
283 SLOT(on_view_triggerIsZero_changed(int)));
284 trace_view_layout->addRow(tr("Show time zero at the trigger"), cb);
285
72df22b8
SA
286 cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling,
287 SLOT(on_view_stickyScrolling_changed(int)));
288 trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb);
bf9f1268 289
72df22b8
SA
290 cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints,
291 SLOT(on_view_showSamplingPoints_changed(int)));
292 trace_view_layout->addRow(tr("Show data &sampling points"), cb);
051ba3b3 293
4521022b
SA
294 cb = create_checkbox(GlobalSettings::Key_View_FillSignalHighAreas,
295 SLOT(on_view_fillSignalHighAreas_changed(int)));
296 trace_view_layout->addRow(tr("Fill high areas of logic signals"), cb);
297
298 ColorButton* high_fill_cb = new ColorButton(parent);
299 high_fill_cb->set_color(QColor::fromRgba(
300 settings.value(GlobalSettings::Key_View_FillSignalHighAreaColor).value<uint32_t>()));
301 connect(high_fill_cb, SIGNAL(selected(QColor)),
302 this, SLOT(on_view_fillSignalHighAreaColor_changed(QColor)));
303 trace_view_layout->addRow(tr("Fill high areas of logic signals"), high_fill_cb);
304
72df22b8
SA
305 cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid,
306 SLOT(on_view_showAnalogMinorGrid_changed(int)));
90ee1ed9
SA
307 trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb);
308
1931b5f9
SA
309 cb = create_checkbox(GlobalSettings::Key_View_ShowHoverMarker,
310 SLOT(on_view_showHoverMarker_changed(int)));
311 trace_view_layout->addRow(tr("Highlight mouse cursor using a vertical marker line"), cb);
312
fb641801
SA
313 QSpinBox *snap_distance_sb = new QSpinBox();
314 snap_distance_sb->setRange(0, 1000);
315 snap_distance_sb->setSuffix(tr(" pixels"));
316 snap_distance_sb->setValue(
317 settings.value(GlobalSettings::Key_View_SnapDistance).toInt());
318 connect(snap_distance_sb, SIGNAL(valueChanged(int)), this,
319 SLOT(on_view_snapDistance_changed(int)));
320 trace_view_layout->addRow(tr("Maximum distance from edges before cursors snap to them"), snap_distance_sb);
321
90ee1ed9
SA
322 QComboBox *thr_disp_mode_cb = new QComboBox();
323 thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
324 thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
325 thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots);
326 thr_disp_mode_cb->setCurrentIndex(
327 settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt());
328 connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)),
329 this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
330 trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb);
4433246b 331
daa54986
SA
332 QSpinBox *default_div_height_sb = new QSpinBox();
333 default_div_height_sb->setRange(20, 1000);
334 default_div_height_sb->setSuffix(tr(" pixels"));
335 default_div_height_sb->setValue(
336 settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt());
337 connect(default_div_height_sb, SIGNAL(valueChanged(int)), this,
338 SLOT(on_view_defaultDivHeight_changed(int)));
339 trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb);
340
48051ccb
SA
341 QSpinBox *default_logic_height_sb = new QSpinBox();
342 default_logic_height_sb->setRange(5, 1000);
343 default_logic_height_sb->setSuffix(tr(" pixels"));
344 default_logic_height_sb->setValue(
345 settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt());
346 connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this,
347 SLOT(on_view_defaultLogicHeight_changed(int)));
348 trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb);
349
bf9f1268
SA
350 return form;
351}
352
1ed996b4 353QWidget *Settings::get_decoder_settings_form(QWidget *parent)
669686c1
SA
354{
355#ifdef ENABLE_DECODE
1ed996b4 356 GlobalSettings settings;
72df22b8 357 QCheckBox *cb;
669686c1
SA
358
359 QWidget *form = new QWidget(parent);
360 QVBoxLayout *form_layout = new QVBoxLayout(form);
361
362 // Decoder settings
363 QGroupBox *decoder_group = new QGroupBox(tr("Decoders"));
364 form_layout->addWidget(decoder_group);
365
366 QFormLayout *decoder_layout = new QFormLayout();
367 decoder_group->setLayout(decoder_layout);
368
72df22b8
SA
369 cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable,
370 SLOT(on_dec_initialStateConfigurable_changed(int)));
371 decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
1cc1c8de 372
1ed996b4
SA
373 // Annotation export settings
374 ann_export_format_ = new QLineEdit();
375 ann_export_format_->setText(
376 settings.value(GlobalSettings::Key_Dec_ExportFormat).toString());
377 connect(ann_export_format_, SIGNAL(textChanged(const QString&)),
378 this, SLOT(on_dec_exportFormat_changed(const QString&)));
379 decoder_layout->addRow(tr("Annotation export format"), ann_export_format_);
39e047cf 380 QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %c: row name; %q: use quotations marks"));
1ed996b4
SA
381 description_1->setAlignment(Qt::AlignRight);
382 decoder_layout->addRow(description_1);
383 QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts"));
384 description_2->setAlignment(Qt::AlignRight);
385 decoder_layout->addRow(description_2);
386
669686c1
SA
387 return form;
388#else
389 (void)parent;
7773ccae 390 return nullptr;
669686c1
SA
391#endif
392}
393
4e4d72b2
SA
394QWidget *Settings::get_about_page(QWidget *parent) const
395{
49719858 396 Application* a = qobject_cast<Application*>(QApplication::instance());
4e4d72b2
SA
397
398 QLabel *icon = new QLabel();
311da121 399 icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg")));
4e4d72b2 400
49719858 401 // Setup the license field with the project homepage link
b804a6da
GS
402 QLabel *gpl_home_info = new QLabel();
403 gpl_home_info->setText(tr("%1<br /><a href=\"http://%2\">%2</a>").arg(
4e4d72b2
SA
404 tr("GNU GPL, version 3 or later"),
405 QApplication::organizationDomain()));
b804a6da 406 gpl_home_info->setOpenExternalLinks(true);
4e4d72b2 407
4e4d72b2 408 QString s;
d008cab1
ML
409
410 s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
411
4e4d72b2
SA
412 s.append("<table>");
413
b804a6da 414 s.append("<tr><td colspan=\"2\"><b>" +
d3d55ad3 415 tr("Versions, libraries and features:") + "</b></td></tr>");
49719858
SA
416 for (pair<QString, QString> &entry : a->get_version_info())
417 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
418 .arg(entry.first, entry.second));
20c80c8a 419
bf84211b
SA
420 s.append("<tr><td colspan=\"2\"></td></tr>");
421 s.append("<tr><td colspan=\"2\"><b>" +
422 tr("Firmware search paths:") + "</b></td></tr>");
49719858
SA
423 for (QString &entry : a->get_fw_path_list())
424 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry));
bf84211b
SA
425
426#ifdef ENABLE_DECODE
427 s.append("<tr><td colspan=\"2\"></td></tr>");
428 s.append("<tr><td colspan=\"2\"><b>" +
429 tr("Protocol decoder search paths:") + "</b></td></tr>");
49719858
SA
430 for (QString &entry : a->get_pd_path_list())
431 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry));
bf84211b
SA
432#endif
433
edfe64fd 434 s.append("<tr><td colspan=\"2\"></td></tr>");
4e4d72b2 435 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 436 tr("Supported hardware drivers:") + "</b></td></tr>");
49719858 437 for (pair<QString, QString> &entry : a->get_driver_list())
d008cab1 438 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
49719858 439 .arg(entry.first, entry.second));
4e4d72b2 440
edfe64fd 441 s.append("<tr><td colspan=\"2\"></td></tr>");
4e4d72b2 442 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 443 tr("Supported input formats:") + "</b></td></tr>");
49719858 444 for (pair<QString, QString> &entry : a->get_input_format_list())
d008cab1 445 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
49719858 446 .arg(entry.first, entry.second));
4e4d72b2 447
edfe64fd 448 s.append("<tr><td colspan=\"2\"></td></tr>");
4e4d72b2 449 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 450 tr("Supported output formats:") + "</b></td></tr>");
49719858 451 for (pair<QString, QString> &entry : a->get_output_format_list())
d008cab1 452 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
49719858 453 .arg(entry.first, entry.second));
4e4d72b2
SA
454
455#ifdef ENABLE_DECODE
edfe64fd 456 s.append("<tr><td colspan=\"2\"></td></tr>");
4e4d72b2 457 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 458 tr("Supported protocol decoders:") + "</b></td></tr>");
49719858 459 for (pair<QString, QString> &entry : a->get_pd_list())
d008cab1 460 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
49719858 461 .arg(entry.first, entry.second));
4e4d72b2
SA
462#endif
463
464 s.append("</table>");
465
466 QTextDocument *supported_doc = new QTextDocument();
467 supported_doc->setHtml(s);
468
469 QTextBrowser *support_list = new QTextBrowser();
470 support_list->setDocument(supported_doc);
471
7d9dd6f4
UH
472 QHBoxLayout *h_layout = new QHBoxLayout();
473 h_layout->setAlignment(Qt::AlignLeft);
474 h_layout->addWidget(icon);
475 h_layout->addWidget(gpl_home_info);
476
477 QVBoxLayout *layout = new QVBoxLayout();
478 layout->addLayout(h_layout);
479 layout->addWidget(support_list);
4e4d72b2
SA
480
481 QWidget *page = new QWidget(parent);
482 page->setLayout(layout);
483
484 return page;
485}
486
bcb4c327
SA
487QWidget *Settings::get_logging_page(QWidget *parent) const
488{
489 GlobalSettings settings;
490
491 // Log level
492 QSpinBox *loglevel_sb = new QSpinBox();
493 loglevel_sb->setMaximum(SR_LOG_SPEW);
494 loglevel_sb->setValue(logging.get_log_level());
495 connect(loglevel_sb, SIGNAL(valueChanged(int)), this,
496 SLOT(on_log_logLevel_changed(int)));
497
498 QHBoxLayout *loglevel_layout = new QHBoxLayout();
499 loglevel_layout->addWidget(new QLabel(tr("Log level:")));
500 loglevel_layout->addWidget(loglevel_sb);
501
502 // Background buffer size
503 QSpinBox *buffersize_sb = new QSpinBox();
504 buffersize_sb->setSuffix(tr(" lines"));
b9a3a67e 505 buffersize_sb->setMinimum(Logging::MIN_BUFFER_SIZE);
bcb4c327
SA
506 buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE);
507 buffersize_sb->setValue(
508 settings.value(GlobalSettings::Key_Log_BufferSize).toInt());
509 connect(buffersize_sb, SIGNAL(valueChanged(int)), this,
510 SLOT(on_log_bufferSize_changed(int)));
511
512 QHBoxLayout *buffersize_layout = new QHBoxLayout();
513 buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:")));
514 buffersize_layout->addWidget(buffersize_sb);
515
516 // Save to file
517 QPushButton *save_log_pb = new QPushButton(
518 QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")),
519 tr("&Save to File"));
520 connect(save_log_pb, SIGNAL(clicked(bool)),
521 this, SLOT(on_log_saveToFile_clicked(bool)));
522
523 // Pop out
524 QPushButton *pop_out_pb = new QPushButton(
525 QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")),
526 tr("&Pop out"));
527 connect(pop_out_pb, SIGNAL(clicked(bool)),
528 this, SLOT(on_log_popOut_clicked(bool)));
529
530 QHBoxLayout *control_layout = new QHBoxLayout();
531 control_layout->addLayout(loglevel_layout);
532 control_layout->addLayout(buffersize_layout);
533 control_layout->addWidget(save_log_pb);
534 control_layout->addWidget(pop_out_pb);
535
536 QVBoxLayout *root_layout = new QVBoxLayout();
537 root_layout->addLayout(control_layout);
538 root_layout->addWidget(log_view_);
539
540 QWidget *page = new QWidget(parent);
541 page->setLayout(root_layout);
542
543 return page;
544}
545
bf9f1268
SA
546void Settings::accept()
547{
2cca9ebf
SA
548 GlobalSettings settings;
549 settings.stop_tracking();
550
bf9f1268
SA
551 QDialog::accept();
552}
553
554void Settings::reject()
555{
2cca9ebf
SA
556 GlobalSettings settings;
557 settings.undo_tracked_changes();
558
bf9f1268
SA
559 QDialog::reject();
560}
561
b14db788
SA
562void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
563{
564 if (!current)
565 current = previous;
566
567 pages->setCurrentIndex(page_list->row(current));
568}
569
37b0bd35
SA
570void Settings::on_general_theme_changed_changed(int state)
571{
572 GlobalSettings settings;
573 settings.setValue(GlobalSettings::Key_General_Theme, state);
574 settings.apply_theme();
a42d2514
SA
575
576 QMessageBox msg(this);
577 msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
578 msg.setIcon(QMessageBox::Question);
579
580 if (settings.current_theme_is_dark()) {
581 msg.setText(tr("You selected a dark theme.\n" \
582 "Should I set the user-adjustable colors to better suit your choice?\n\n" \
583 "Please keep in mind that PulseView may need a restart to display correctly."));
584 if (msg.exec() == QMessageBox::Yes)
585 settings.set_dark_theme_default_colors();
586 } else {
587 msg.setText(tr("You selected a bright theme.\n" \
588 "Should I set the user-adjustable colors to better suit your choice?\n\n" \
589 "Please keep in mind that PulseView may need a restart to display correctly."));
590 if (msg.exec() == QMessageBox::Yes)
591 settings.set_bright_theme_default_colors();
592 }
37b0bd35
SA
593}
594
374c697f
SA
595void Settings::on_general_style_changed(int state)
596{
597 GlobalSettings settings;
598
599 if (state == 0)
600 settings.setValue(GlobalSettings::Key_General_Style, "");
601 else
602 settings.setValue(GlobalSettings::Key_General_Style,
603 QStyleFactory::keys().at(state - 1));
604
605 settings.apply_theme();
606}
607
e91fb166 608void Settings::on_view_zoomToFitDuringAcq_changed(int state)
bf9f1268
SA
609{
610 GlobalSettings settings;
e91fb166 611 settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false);
bf9f1268
SA
612}
613
28ceff25
SA
614void Settings::on_view_zoomToFitAfterAcq_changed(int state)
615{
616 GlobalSettings settings;
617 settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false);
618}
619
ffc00fdd
C
620void Settings::on_view_triggerIsZero_changed(int state)
621{
622 GlobalSettings settings;
623 settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false);
624}
625
641574bc 626void Settings::on_view_coloredBG_changed(int state)
bf9f1268
SA
627{
628 GlobalSettings settings;
641574bc 629 settings.setValue(GlobalSettings::Key_View_ColoredBG, state ? true : false);
bf9f1268
SA
630}
631
87a97d8a
SA
632void Settings::on_view_stickyScrolling_changed(int state)
633{
634 GlobalSettings settings;
635 settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
636}
637
051ba3b3
UH
638void Settings::on_view_showSamplingPoints_changed(int state)
639{
640 GlobalSettings settings;
641 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
642}
87a97d8a 643
4521022b
SA
644void Settings::on_view_fillSignalHighAreas_changed(int state)
645{
646 GlobalSettings settings;
647 settings.setValue(GlobalSettings::Key_View_FillSignalHighAreas, state ? true : false);
648}
649
650void Settings::on_view_fillSignalHighAreaColor_changed(QColor color)
651{
652 GlobalSettings settings;
653 settings.setValue(GlobalSettings::Key_View_FillSignalHighAreaColor, color.rgba());
654}
655
8ad61f40
UH
656void Settings::on_view_showAnalogMinorGrid_changed(int state)
657{
658 GlobalSettings settings;
659 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
660}
661
1931b5f9
SA
662void Settings::on_view_showHoverMarker_changed(int state)
663{
664 GlobalSettings settings;
665 settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, state ? true : false);
666}
667
fb641801
SA
668void Settings::on_view_snapDistance_changed(int value)
669{
670 GlobalSettings settings;
671 settings.setValue(GlobalSettings::Key_View_SnapDistance, value);
672}
673
90ee1ed9 674void Settings::on_view_conversionThresholdDispMode_changed(int state)
4433246b
SA
675{
676 GlobalSettings settings;
90ee1ed9 677 settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state);
4433246b
SA
678}
679
daa54986
SA
680void Settings::on_view_defaultDivHeight_changed(int value)
681{
682 GlobalSettings settings;
683 settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value);
684}
685
48051ccb
SA
686void Settings::on_view_defaultLogicHeight_changed(int value)
687{
688 GlobalSettings settings;
689 settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value);
690}
691
1ed996b4 692#ifdef ENABLE_DECODE
1cc1c8de
SA
693void Settings::on_dec_initialStateConfigurable_changed(int state)
694{
695 GlobalSettings settings;
696 settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
697}
698
1ed996b4
SA
699void Settings::on_dec_exportFormat_changed(const QString &text)
700{
701 GlobalSettings settings;
702 settings.setValue(GlobalSettings::Key_Dec_ExportFormat, text);
703}
704#endif
705
bcb4c327
SA
706void Settings::on_log_logLevel_changed(int value)
707{
708 logging.set_log_level(value);
709}
710
711void Settings::on_log_bufferSize_changed(int value)
712{
713 GlobalSettings settings;
714 settings.setValue(GlobalSettings::Key_Log_BufferSize, value);
715}
716
717void Settings::on_log_saveToFile_clicked(bool checked)
718{
719 (void)checked;
720
721 const QString file_name = QFileDialog::getSaveFileName(
722 this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)"));
723
724 if (file_name.isEmpty())
725 return;
726
727 QFile file(file_name);
728 if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
729 QTextStream out_stream(&file);
730 out_stream << log_view_->toPlainText();
731
732 if (out_stream.status() == QTextStream::Ok) {
733 QMessageBox msg(this);
734 msg.setText(tr("Success"));
735 msg.setInformativeText(tr("Log saved to %1.").arg(file_name));
736 msg.setStandardButtons(QMessageBox::Ok);
737 msg.setIcon(QMessageBox::Information);
738 msg.exec();
739
740 return;
741 }
742 }
743
744 QMessageBox msg(this);
745 msg.setText(tr("Error"));
746 msg.setInformativeText(tr("File %1 could not be written to.").arg(file_name));
747 msg.setStandardButtons(QMessageBox::Ok);
748 msg.setIcon(QMessageBox::Warning);
749 msg.exec();
750}
751
752void Settings::on_log_popOut_clicked(bool checked)
753{
754 (void)checked;
755
756 // Create the window as a sub-window so it closes when the main window closes
37134086 757 QMainWindow *window = new QMainWindow(nullptr, Qt::SubWindow);
bcb4c327
SA
758
759 window->setObjectName(QString::fromUtf8("Log Window"));
760 window->setWindowTitle(tr("%1 Log").arg(PV_TITLE));
761
762 // Use same width/height as the settings dialog
763 window->resize(width(), height());
764
765 window->setCentralWidget(create_log_view());
766 window->show();
767}
768
bf9f1268
SA
769} // namespace dialogs
770} // namespace pv