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