]> sigrok.org Git - pulseview.git/blame - pv/dialogs/settings.cpp
Add "start acquisition for all devices" option
[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;
8962d7b3 207 QCheckBox *cb;
37b0bd35
SA
208
209 QWidget *form = new QWidget(parent);
210 QVBoxLayout *form_layout = new QVBoxLayout(form);
211
212 // General settings
213 QGroupBox *general_group = new QGroupBox(tr("General"));
214 form_layout->addWidget(general_group);
215
216 QFormLayout *general_layout = new QFormLayout();
217 general_group->setLayout(general_layout);
218
380f4ee6
SA
219 // Generate language combobox
220 QComboBox *language_cb = new QComboBox();
221 Application* a = qobject_cast<Application*>(QApplication::instance());
222
223 QString current_language = settings.value(GlobalSettings::Key_General_Language).toString();
49fee853 224 for (const QString& language : a->get_languages()) {
c8e2f09b
SA
225 const QLocale locale = QLocale(language);
226 const QString desc = locale.languageToString(locale.language());
380f4ee6
SA
227 language_cb->addItem(desc, language);
228
229 if (language == current_language) {
230 int index = language_cb->findText(desc, Qt::MatchFixedString);
231 language_cb->setCurrentIndex(index);
232 }
233 }
234 connect(language_cb, SIGNAL(currentIndexChanged(const QString&)),
235 this, SLOT(on_general_language_changed(const QString&)));
236 general_layout->addRow(tr("User interface language"), language_cb);
237
238 // Theme combobox
37b0bd35 239 QComboBox *theme_cb = new QComboBox();
f4ab4b5c 240 for (const pair<QString, QString>& entry : Themes)
37b0bd35
SA
241 theme_cb->addItem(entry.first, entry.second);
242
243 theme_cb->setCurrentIndex(
244 settings.value(GlobalSettings::Key_General_Theme).toInt());
245 connect(theme_cb, SIGNAL(currentIndexChanged(int)),
380f4ee6 246 this, SLOT(on_general_theme_changed(int)));
37b0bd35
SA
247 general_layout->addRow(tr("User interface theme"), theme_cb);
248
249 QLabel *description_1 = new QLabel(tr("(You may need to restart PulseView for all UI elements to update)"));
250 description_1->setAlignment(Qt::AlignRight);
251 general_layout->addRow(description_1);
252
380f4ee6 253 // Style combobox
374c697f
SA
254 QComboBox *style_cb = new QComboBox();
255 style_cb->addItem(tr("System Default"), "");
256 for (QString& s : QStyleFactory::keys())
257 style_cb->addItem(s, s);
258
259 const QString current_style =
260 settings.value(GlobalSettings::Key_General_Style).toString();
261 if (current_style.isEmpty())
262 style_cb->setCurrentIndex(0);
263 else
c409988b 264 style_cb->setCurrentIndex(style_cb->findText(current_style, nullptr));
374c697f
SA
265
266 connect(style_cb, SIGNAL(currentIndexChanged(int)),
267 this, SLOT(on_general_style_changed(int)));
268 general_layout->addRow(tr("Qt widget style"), style_cb);
269
270 QLabel *description_2 = new QLabel(tr("(Dark themes look best with the Fusion style)"));
271 description_2->setAlignment(Qt::AlignRight);
272 general_layout->addRow(description_2);
273
380f4ee6 274 // Misc
8962d7b3
SA
275 cb = create_checkbox(GlobalSettings::Key_General_SaveWithSetup,
276 SLOT(on_general_save_with_setup_changed(int)));
277 general_layout->addRow(tr("Save session &setup along with .sr file"), cb);
278
5d58e6ce
SA
279 cb = create_checkbox(GlobalSettings::Key_General_StartAllSessions,
280 SLOT(on_general_start_all_sessions_changed(int)));
281 general_layout->addRow(tr("Start acquisition for all open sessions when clicking 'Run'"), cb);
282
283
37b0bd35
SA
284 return form;
285}
286
72df22b8
SA
287QWidget *Settings::get_view_settings_form(QWidget *parent) const
288{
daa54986 289 GlobalSettings settings;
72df22b8
SA
290 QCheckBox *cb;
291
bf9f1268
SA
292 QWidget *form = new QWidget(parent);
293 QVBoxLayout *form_layout = new QVBoxLayout(form);
294
295 // Trace view settings
296 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
297 form_layout->addWidget(trace_view_group);
298
299 QFormLayout *trace_view_layout = new QFormLayout();
300 trace_view_group->setLayout(trace_view_layout);
301
641574bc
SA
302 cb = create_checkbox(GlobalSettings::Key_View_ColoredBG,
303 SLOT(on_view_coloredBG_changed(int)));
304 trace_view_layout->addRow(tr("Use colored trace &background"), cb);
bf9f1268 305
e91fb166
SA
306 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq,
307 SLOT(on_view_zoomToFitDuringAcq_changed(int)));
308 trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb);
87a97d8a 309
28ceff25
SA
310 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq,
311 SLOT(on_view_zoomToFitAfterAcq_changed(int)));
312 trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb);
313
ffc00fdd
C
314 cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime,
315 SLOT(on_view_triggerIsZero_changed(int)));
316 trace_view_layout->addRow(tr("Show time zero at the trigger"), cb);
317
72df22b8
SA
318 cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling,
319 SLOT(on_view_stickyScrolling_changed(int)));
320 trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb);
bf9f1268 321
72df22b8
SA
322 cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints,
323 SLOT(on_view_showSamplingPoints_changed(int)));
324 trace_view_layout->addRow(tr("Show data &sampling points"), cb);
051ba3b3 325
4521022b
SA
326 cb = create_checkbox(GlobalSettings::Key_View_FillSignalHighAreas,
327 SLOT(on_view_fillSignalHighAreas_changed(int)));
328 trace_view_layout->addRow(tr("Fill high areas of logic signals"), cb);
329
330 ColorButton* high_fill_cb = new ColorButton(parent);
331 high_fill_cb->set_color(QColor::fromRgba(
332 settings.value(GlobalSettings::Key_View_FillSignalHighAreaColor).value<uint32_t>()));
333 connect(high_fill_cb, SIGNAL(selected(QColor)),
334 this, SLOT(on_view_fillSignalHighAreaColor_changed(QColor)));
829b23f6 335 trace_view_layout->addRow(tr("Color to fill high areas of logic signals with"), high_fill_cb);
4521022b 336
72df22b8
SA
337 cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid,
338 SLOT(on_view_showAnalogMinorGrid_changed(int)));
90ee1ed9
SA
339 trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb);
340
1931b5f9
SA
341 cb = create_checkbox(GlobalSettings::Key_View_ShowHoverMarker,
342 SLOT(on_view_showHoverMarker_changed(int)));
343 trace_view_layout->addRow(tr("Highlight mouse cursor using a vertical marker line"), cb);
344
fb641801
SA
345 QSpinBox *snap_distance_sb = new QSpinBox();
346 snap_distance_sb->setRange(0, 1000);
347 snap_distance_sb->setSuffix(tr(" pixels"));
348 snap_distance_sb->setValue(
349 settings.value(GlobalSettings::Key_View_SnapDistance).toInt());
350 connect(snap_distance_sb, SIGNAL(valueChanged(int)), this,
351 SLOT(on_view_snapDistance_changed(int)));
0ea2cfc5 352 trace_view_layout->addRow(tr("Maximum distance from edges before markers snap to them"), snap_distance_sb);
fb641801 353
c04f5a29
SA
354 ColorButton* cursor_fill_cb = new ColorButton(parent);
355 cursor_fill_cb->set_color(QColor::fromRgba(
356 settings.value(GlobalSettings::Key_View_CursorFillColor).value<uint32_t>()));
357 connect(cursor_fill_cb, SIGNAL(selected(QColor)),
358 this, SLOT(on_view_cursorFillColor_changed(QColor)));
359 trace_view_layout->addRow(tr("Color to fill cursor area with"), cursor_fill_cb);
360
90ee1ed9
SA
361 QComboBox *thr_disp_mode_cb = new QComboBox();
362 thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
363 thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
364 thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots);
365 thr_disp_mode_cb->setCurrentIndex(
366 settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt());
367 connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)),
368 this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
369 trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb);
4433246b 370
daa54986
SA
371 QSpinBox *default_div_height_sb = new QSpinBox();
372 default_div_height_sb->setRange(20, 1000);
373 default_div_height_sb->setSuffix(tr(" pixels"));
374 default_div_height_sb->setValue(
375 settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt());
376 connect(default_div_height_sb, SIGNAL(valueChanged(int)), this,
377 SLOT(on_view_defaultDivHeight_changed(int)));
378 trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb);
379
48051ccb
SA
380 QSpinBox *default_logic_height_sb = new QSpinBox();
381 default_logic_height_sb->setRange(5, 1000);
382 default_logic_height_sb->setSuffix(tr(" pixels"));
383 default_logic_height_sb->setValue(
384 settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt());
385 connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this,
386 SLOT(on_view_defaultLogicHeight_changed(int)));
387 trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb);
388
bf9f1268
SA
389 return form;
390}
391
1ed996b4 392QWidget *Settings::get_decoder_settings_form(QWidget *parent)
669686c1
SA
393{
394#ifdef ENABLE_DECODE
1ed996b4 395 GlobalSettings settings;
72df22b8 396 QCheckBox *cb;
669686c1
SA
397
398 QWidget *form = new QWidget(parent);
399 QVBoxLayout *form_layout = new QVBoxLayout(form);
400
401 // Decoder settings
402 QGroupBox *decoder_group = new QGroupBox(tr("Decoders"));
403 form_layout->addWidget(decoder_group);
404
405 QFormLayout *decoder_layout = new QFormLayout();
406 decoder_group->setLayout(decoder_layout);
407
72df22b8
SA
408 cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable,
409 SLOT(on_dec_initialStateConfigurable_changed(int)));
410 decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
1cc1c8de 411
ab185f78
SA
412 cb = create_checkbox(GlobalSettings::Key_Dec_AlwaysShowAllRows,
413 SLOT(on_dec_alwaysshowallrows_changed(int)));
414 decoder_layout->addRow(tr("Always show all &rows, even if no annotation is visible"), cb);
415
1ed996b4
SA
416 // Annotation export settings
417 ann_export_format_ = new QLineEdit();
418 ann_export_format_->setText(
419 settings.value(GlobalSettings::Key_Dec_ExportFormat).toString());
420 connect(ann_export_format_, SIGNAL(textChanged(const QString&)),
421 this, SLOT(on_dec_exportFormat_changed(const QString&)));
422 decoder_layout->addRow(tr("Annotation export format"), ann_export_format_);
761f8302 423 QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %r: row name; %c: class name"));
1ed996b4
SA
424 description_1->setAlignment(Qt::AlignRight);
425 decoder_layout->addRow(description_1);
761f8302 426 QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts; %q: use quotation marks"));
1ed996b4
SA
427 description_2->setAlignment(Qt::AlignRight);
428 decoder_layout->addRow(description_2);
429
669686c1
SA
430 return form;
431#else
432 (void)parent;
7773ccae 433 return nullptr;
669686c1
SA
434#endif
435}
436
4e4d72b2
SA
437QWidget *Settings::get_about_page(QWidget *parent) const
438{
49719858 439 Application* a = qobject_cast<Application*>(QApplication::instance());
4e4d72b2
SA
440
441 QLabel *icon = new QLabel();
311da121 442 icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg")));
4e4d72b2 443
49719858 444 // Setup the license field with the project homepage link
b804a6da
GS
445 QLabel *gpl_home_info = new QLabel();
446 gpl_home_info->setText(tr("%1<br /><a href=\"http://%2\">%2</a>").arg(
4e4d72b2
SA
447 tr("GNU GPL, version 3 or later"),
448 QApplication::organizationDomain()));
b804a6da 449 gpl_home_info->setOpenExternalLinks(true);
4e4d72b2 450
4e4d72b2 451 QString s;
d008cab1
ML
452
453 s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
454
4e4d72b2
SA
455 s.append("<table>");
456
b804a6da 457 s.append("<tr><td colspan=\"2\"><b>" +
d3d55ad3 458 tr("Versions, libraries and features:") + "</b></td></tr>");
49719858
SA
459 for (pair<QString, QString> &entry : a->get_version_info())
460 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
461 .arg(entry.first, entry.second));
20c80c8a 462
bf84211b
SA
463 s.append("<tr><td colspan=\"2\"></td></tr>");
464 s.append("<tr><td colspan=\"2\"><b>" +
465 tr("Firmware search paths:") + "</b></td></tr>");
49719858
SA
466 for (QString &entry : a->get_fw_path_list())
467 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry));
bf84211b
SA
468
469#ifdef ENABLE_DECODE
470 s.append("<tr><td colspan=\"2\"></td></tr>");
471 s.append("<tr><td colspan=\"2\"><b>" +
472 tr("Protocol decoder search paths:") + "</b></td></tr>");
49719858
SA
473 for (QString &entry : a->get_pd_path_list())
474 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry));
9d307c60 475 s.append(tr("<tr><td colspan=\"2\">(Note: Set environment variable SIGROKDECODE_DIR to add a custom directory)</td></tr>"));
bf84211b
SA
476#endif
477
edfe64fd 478 s.append("<tr><td colspan=\"2\"></td></tr>");
4e4d72b2 479 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 480 tr("Supported hardware drivers:") + "</b></td></tr>");
49719858 481 for (pair<QString, QString> &entry : a->get_driver_list())
d008cab1 482 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
49719858 483 .arg(entry.first, entry.second));
4e4d72b2 484
edfe64fd 485 s.append("<tr><td colspan=\"2\"></td></tr>");
4e4d72b2 486 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 487 tr("Supported input formats:") + "</b></td></tr>");
49719858 488 for (pair<QString, QString> &entry : a->get_input_format_list())
d008cab1 489 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
49719858 490 .arg(entry.first, entry.second));
4e4d72b2 491
edfe64fd 492 s.append("<tr><td colspan=\"2\"></td></tr>");
4e4d72b2 493 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 494 tr("Supported output formats:") + "</b></td></tr>");
49719858 495 for (pair<QString, QString> &entry : a->get_output_format_list())
d008cab1 496 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
49719858 497 .arg(entry.first, entry.second));
4e4d72b2
SA
498
499#ifdef ENABLE_DECODE
edfe64fd 500 s.append("<tr><td colspan=\"2\"></td></tr>");
4e4d72b2 501 s.append("<tr><td colspan=\"2\"><b>" +
c063290a 502 tr("Supported protocol decoders:") + "</b></td></tr>");
49719858 503 for (pair<QString, QString> &entry : a->get_pd_list())
d008cab1 504 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
49719858 505 .arg(entry.first, entry.second));
4e4d72b2
SA
506#endif
507
c8e2f09b
SA
508 s.append("<tr><td colspan=\"2\"></td></tr>");
509 s.append("<tr><td colspan=\"2\"><b>" +
510 tr("Available Translations:") + "</b></td></tr>");
511 for (const QString& language : a->get_languages()) {
512 if (language == "en")
513 continue;
514
515 const QLocale locale = QLocale(language);
516 const QString desc = locale.languageToString(locale.language());
517 const QString editors = a->get_language_editors(language);
518
519 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>(%2)</td></tr>")
520 .arg(desc, editors));
521 }
522
4e4d72b2
SA
523 s.append("</table>");
524
525 QTextDocument *supported_doc = new QTextDocument();
526 supported_doc->setHtml(s);
527
528 QTextBrowser *support_list = new QTextBrowser();
529 support_list->setDocument(supported_doc);
530
7d9dd6f4
UH
531 QHBoxLayout *h_layout = new QHBoxLayout();
532 h_layout->setAlignment(Qt::AlignLeft);
533 h_layout->addWidget(icon);
534 h_layout->addWidget(gpl_home_info);
535
536 QVBoxLayout *layout = new QVBoxLayout();
537 layout->addLayout(h_layout);
538 layout->addWidget(support_list);
4e4d72b2
SA
539
540 QWidget *page = new QWidget(parent);
541 page->setLayout(layout);
542
543 return page;
544}
545
bcb4c327
SA
546QWidget *Settings::get_logging_page(QWidget *parent) const
547{
548 GlobalSettings settings;
549
550 // Log level
551 QSpinBox *loglevel_sb = new QSpinBox();
552 loglevel_sb->setMaximum(SR_LOG_SPEW);
553 loglevel_sb->setValue(logging.get_log_level());
554 connect(loglevel_sb, SIGNAL(valueChanged(int)), this,
555 SLOT(on_log_logLevel_changed(int)));
556
557 QHBoxLayout *loglevel_layout = new QHBoxLayout();
558 loglevel_layout->addWidget(new QLabel(tr("Log level:")));
559 loglevel_layout->addWidget(loglevel_sb);
560
561 // Background buffer size
562 QSpinBox *buffersize_sb = new QSpinBox();
563 buffersize_sb->setSuffix(tr(" lines"));
b9a3a67e 564 buffersize_sb->setMinimum(Logging::MIN_BUFFER_SIZE);
bcb4c327
SA
565 buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE);
566 buffersize_sb->setValue(
567 settings.value(GlobalSettings::Key_Log_BufferSize).toInt());
568 connect(buffersize_sb, SIGNAL(valueChanged(int)), this,
569 SLOT(on_log_bufferSize_changed(int)));
570
571 QHBoxLayout *buffersize_layout = new QHBoxLayout();
572 buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:")));
573 buffersize_layout->addWidget(buffersize_sb);
574
575 // Save to file
576 QPushButton *save_log_pb = new QPushButton(
577 QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")),
578 tr("&Save to File"));
579 connect(save_log_pb, SIGNAL(clicked(bool)),
580 this, SLOT(on_log_saveToFile_clicked(bool)));
581
582 // Pop out
583 QPushButton *pop_out_pb = new QPushButton(
584 QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")),
585 tr("&Pop out"));
586 connect(pop_out_pb, SIGNAL(clicked(bool)),
587 this, SLOT(on_log_popOut_clicked(bool)));
588
589 QHBoxLayout *control_layout = new QHBoxLayout();
590 control_layout->addLayout(loglevel_layout);
591 control_layout->addLayout(buffersize_layout);
592 control_layout->addWidget(save_log_pb);
593 control_layout->addWidget(pop_out_pb);
594
595 QVBoxLayout *root_layout = new QVBoxLayout();
596 root_layout->addLayout(control_layout);
597 root_layout->addWidget(log_view_);
598
599 QWidget *page = new QWidget(parent);
600 page->setLayout(root_layout);
601
602 return page;
603}
604
bf9f1268
SA
605void Settings::accept()
606{
2cca9ebf
SA
607 GlobalSettings settings;
608 settings.stop_tracking();
609
bf9f1268
SA
610 QDialog::accept();
611}
612
613void Settings::reject()
614{
2cca9ebf
SA
615 GlobalSettings settings;
616 settings.undo_tracked_changes();
617
bf9f1268
SA
618 QDialog::reject();
619}
620
b14db788
SA
621void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
622{
623 if (!current)
624 current = previous;
625
626 pages->setCurrentIndex(page_list->row(current));
627}
628
380f4ee6
SA
629void Settings::on_general_language_changed(const QString &text)
630{
631 GlobalSettings settings;
632 Application* a = qobject_cast<Application*>(QApplication::instance());
633
49fee853 634 for (const QString& language : a->get_languages()) {
380f4ee6
SA
635 QLocale locale = QLocale(language);
636 QString desc = locale.languageToString(locale.language());
637
638 if (text == desc)
639 settings.setValue(GlobalSettings::Key_General_Language, language);
640 }
641}
642
643void Settings::on_general_theme_changed(int value)
37b0bd35
SA
644{
645 GlobalSettings settings;
380f4ee6 646 settings.setValue(GlobalSettings::Key_General_Theme, value);
37b0bd35 647 settings.apply_theme();
a42d2514
SA
648
649 QMessageBox msg(this);
650 msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
651 msg.setIcon(QMessageBox::Question);
652
653 if (settings.current_theme_is_dark()) {
654 msg.setText(tr("You selected a dark theme.\n" \
655 "Should I set the user-adjustable colors to better suit your choice?\n\n" \
656 "Please keep in mind that PulseView may need a restart to display correctly."));
657 if (msg.exec() == QMessageBox::Yes)
658 settings.set_dark_theme_default_colors();
659 } else {
660 msg.setText(tr("You selected a bright theme.\n" \
661 "Should I set the user-adjustable colors to better suit your choice?\n\n" \
662 "Please keep in mind that PulseView may need a restart to display correctly."));
663 if (msg.exec() == QMessageBox::Yes)
664 settings.set_bright_theme_default_colors();
665 }
37b0bd35
SA
666}
667
380f4ee6 668void Settings::on_general_style_changed(int value)
374c697f
SA
669{
670 GlobalSettings settings;
671
380f4ee6 672 if (value == 0)
374c697f
SA
673 settings.setValue(GlobalSettings::Key_General_Style, "");
674 else
675 settings.setValue(GlobalSettings::Key_General_Style,
380f4ee6 676 QStyleFactory::keys().at(value - 1));
374c697f
SA
677
678 settings.apply_theme();
679}
680
8962d7b3
SA
681void Settings::on_general_save_with_setup_changed(int state)
682{
683 GlobalSettings settings;
684 settings.setValue(GlobalSettings::Key_General_SaveWithSetup, state ? true : false);
685}
686
5d58e6ce
SA
687void Settings::on_general_start_all_sessions_changed(int state)
688{
689 GlobalSettings settings;
690 settings.setValue(GlobalSettings::Key_General_StartAllSessions, state ? true : false);
691}
692
e91fb166 693void Settings::on_view_zoomToFitDuringAcq_changed(int state)
bf9f1268
SA
694{
695 GlobalSettings settings;
e91fb166 696 settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false);
bf9f1268
SA
697}
698
28ceff25
SA
699void Settings::on_view_zoomToFitAfterAcq_changed(int state)
700{
701 GlobalSettings settings;
702 settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false);
703}
704
ffc00fdd
C
705void Settings::on_view_triggerIsZero_changed(int state)
706{
707 GlobalSettings settings;
708 settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false);
709}
710
641574bc 711void Settings::on_view_coloredBG_changed(int state)
bf9f1268
SA
712{
713 GlobalSettings settings;
641574bc 714 settings.setValue(GlobalSettings::Key_View_ColoredBG, state ? true : false);
bf9f1268
SA
715}
716
87a97d8a
SA
717void Settings::on_view_stickyScrolling_changed(int state)
718{
719 GlobalSettings settings;
720 settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
721}
722
051ba3b3
UH
723void Settings::on_view_showSamplingPoints_changed(int state)
724{
725 GlobalSettings settings;
726 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
727}
87a97d8a 728
4521022b
SA
729void Settings::on_view_fillSignalHighAreas_changed(int state)
730{
731 GlobalSettings settings;
732 settings.setValue(GlobalSettings::Key_View_FillSignalHighAreas, state ? true : false);
733}
734
735void Settings::on_view_fillSignalHighAreaColor_changed(QColor color)
736{
737 GlobalSettings settings;
738 settings.setValue(GlobalSettings::Key_View_FillSignalHighAreaColor, color.rgba());
739}
740
8ad61f40
UH
741void Settings::on_view_showAnalogMinorGrid_changed(int state)
742{
743 GlobalSettings settings;
744 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
745}
746
1931b5f9
SA
747void Settings::on_view_showHoverMarker_changed(int state)
748{
749 GlobalSettings settings;
750 settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, state ? true : false);
751}
752
fb641801
SA
753void Settings::on_view_snapDistance_changed(int value)
754{
755 GlobalSettings settings;
756 settings.setValue(GlobalSettings::Key_View_SnapDistance, value);
757}
758
c04f5a29
SA
759void Settings::on_view_cursorFillColor_changed(QColor color)
760{
761 GlobalSettings settings;
762 settings.setValue(GlobalSettings::Key_View_CursorFillColor, color.rgba());
763}
764
90ee1ed9 765void Settings::on_view_conversionThresholdDispMode_changed(int state)
4433246b
SA
766{
767 GlobalSettings settings;
90ee1ed9 768 settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state);
4433246b
SA
769}
770
daa54986
SA
771void Settings::on_view_defaultDivHeight_changed(int value)
772{
773 GlobalSettings settings;
774 settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value);
775}
776
48051ccb
SA
777void Settings::on_view_defaultLogicHeight_changed(int value)
778{
779 GlobalSettings settings;
780 settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value);
781}
782
1ed996b4 783#ifdef ENABLE_DECODE
1cc1c8de
SA
784void Settings::on_dec_initialStateConfigurable_changed(int state)
785{
786 GlobalSettings settings;
787 settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
788}
789
1ed996b4
SA
790void Settings::on_dec_exportFormat_changed(const QString &text)
791{
792 GlobalSettings settings;
793 settings.setValue(GlobalSettings::Key_Dec_ExportFormat, text);
794}
ab185f78
SA
795
796void Settings::on_dec_alwaysshowallrows_changed(int state)
797{
798 GlobalSettings settings;
799 settings.setValue(GlobalSettings::Key_Dec_AlwaysShowAllRows, state ? true : false);
800}
1ed996b4
SA
801#endif
802
bcb4c327
SA
803void Settings::on_log_logLevel_changed(int value)
804{
805 logging.set_log_level(value);
806}
807
808void Settings::on_log_bufferSize_changed(int value)
809{
810 GlobalSettings settings;
811 settings.setValue(GlobalSettings::Key_Log_BufferSize, value);
812}
813
814void Settings::on_log_saveToFile_clicked(bool checked)
815{
816 (void)checked;
817
818 const QString file_name = QFileDialog::getSaveFileName(
819 this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)"));
820
821 if (file_name.isEmpty())
822 return;
823
824 QFile file(file_name);
825 if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
826 QTextStream out_stream(&file);
827 out_stream << log_view_->toPlainText();
828
829 if (out_stream.status() == QTextStream::Ok) {
830 QMessageBox msg(this);
970fca0d 831 msg.setText(tr("Success") + "\n\n" + tr("Log saved to %1.").arg(file_name));
bcb4c327
SA
832 msg.setStandardButtons(QMessageBox::Ok);
833 msg.setIcon(QMessageBox::Information);
834 msg.exec();
835
836 return;
837 }
838 }
839
840 QMessageBox msg(this);
970fca0d 841 msg.setText(tr("Error") + "\n\n" + tr("File %1 could not be written to.").arg(file_name));
bcb4c327
SA
842 msg.setStandardButtons(QMessageBox::Ok);
843 msg.setIcon(QMessageBox::Warning);
844 msg.exec();
845}
846
847void Settings::on_log_popOut_clicked(bool checked)
848{
849 (void)checked;
850
851 // Create the window as a sub-window so it closes when the main window closes
37134086 852 QMainWindow *window = new QMainWindow(nullptr, Qt::SubWindow);
bcb4c327
SA
853
854 window->setObjectName(QString::fromUtf8("Log Window"));
855 window->setWindowTitle(tr("%1 Log").arg(PV_TITLE));
856
857 // Use same width/height as the settings dialog
858 window->resize(width(), height());
859
860 window->setCentralWidget(create_log_view());
861 window->show();
862}
863
bf9f1268
SA
864} // namespace dialogs
865} // namespace pv