]> sigrok.org Git - pulseview.git/blame_incremental - pv/dialogs/settings.cpp
pv: adjust application source code for Qt6 support
[pulseview.git] / pv / dialogs / settings.cpp
... / ...
CommitLineData
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "config.h"
21
22#include <glib.h>
23
24#include <QApplication>
25#include <QComboBox>
26#include <QDialogButtonBox>
27#include <QFileDialog>
28#include <QFormLayout>
29#include <QGroupBox>
30#include <QHBoxLayout>
31#include <QLabel>
32#include <QMainWindow>
33#include <QMessageBox>
34#include <QPushButton>
35#include <QScrollBar>
36#include <QSpinBox>
37#include <QString>
38#include <QStyleFactory>
39#include <QTextBrowser>
40#include <QTextDocument>
41#include <QTextStream>
42#include <QVBoxLayout>
43
44#include "settings.hpp"
45
46#include "pv/application.hpp"
47#include "pv/devicemanager.hpp"
48#include "pv/globalsettings.hpp"
49#include "pv/logging.hpp"
50#include "pv/widgets/colorbutton.hpp"
51
52#include <libsigrokcxx/libsigrokcxx.hpp>
53
54#ifdef ENABLE_DECODE
55#include <libsigrokdecode/libsigrokdecode.h>
56#endif
57
58using pv::widgets::ColorButton;
59
60namespace pv {
61namespace dialogs {
62
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
86Settings::Settings(DeviceManager &device_manager, QWidget *parent) :
87 QDialog(parent),
88 device_manager_(device_manager)
89{
90 resize(600, 400);
91
92 // Create log view
93 log_view_ = create_log_view();
94
95 // Create pages
96 page_list = new PageListWidget();
97 page_list->setViewMode(QListView::ListMode);
98 page_list->setMovement(QListView::Static);
99 page_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
100
101 pages = new QStackedWidget;
102 create_pages();
103 page_list->setCurrentIndex(page_list->model()->index(0, 0));
104
105 // Create the rest of the dialog
106 QHBoxLayout *tab_layout = new QHBoxLayout;
107 tab_layout->addWidget(page_list);
108 tab_layout->addWidget(pages, Qt::AlignLeft);
109
110 QDialogButtonBox *button_box = new QDialogButtonBox(
111 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
112
113 QVBoxLayout* root_layout = new QVBoxLayout(this);
114 root_layout->addLayout(tab_layout);
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()));
119 connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
120 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
121
122 // Start to record changes
123 GlobalSettings settings;
124 settings.start_tracking();
125}
126
127void Settings::create_pages()
128{
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
138 // View page
139 pages->addWidget(get_view_settings_form(pages));
140
141 QListWidgetItem *viewButton = new QListWidgetItem(page_list);
142 viewButton->setIcon(QIcon(":/icons/settings-views.svg"));
143 viewButton->setText(tr("Views"));
144 viewButton->setTextAlignment(Qt::AlignVCenter);
145 viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
146
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"));
154 decoderButton->setTextAlignment(Qt::AlignVCenter);
155 decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
156#endif
157
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"));
164 aboutButton->setTextAlignment(Qt::AlignVCenter);
165 aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
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"));
173 loggingButton->setTextAlignment(Qt::AlignVCenter);
174 loggingButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
175}
176
177QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const
178{
179 GlobalSettings settings;
180
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
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
204QWidget *Settings::get_general_settings_form(QWidget *parent) const
205{
206 GlobalSettings settings;
207 QCheckBox *cb;
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 // 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, "en").toString();
224 for (const QString& language : a->get_languages()) {
225 const QLocale locale = QLocale(language);
226 const QString desc = locale.languageToString(locale.language());
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#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
235 connect(language_cb, SIGNAL(currentTextChanged(const QString&)),
236 this, SLOT(on_general_language_changed(const QString&)));
237#else
238 connect(language_cb, SIGNAL(currentIndexChanged(const QString&)),
239 this, SLOT(on_general_language_changed(const QString&)));
240#endif
241 general_layout->addRow(tr("User interface language"), language_cb);
242
243 // Theme combobox
244 QComboBox *theme_cb = new QComboBox();
245 for (const pair<QString, QString>& entry : Themes)
246 theme_cb->addItem(entry.first, entry.second);
247
248 theme_cb->setCurrentIndex(
249 settings.value(GlobalSettings::Key_General_Theme).toInt());
250 connect(theme_cb, SIGNAL(currentIndexChanged(int)),
251 this, SLOT(on_general_theme_changed(int)));
252 general_layout->addRow(tr("User interface theme"), theme_cb);
253
254 QLabel *description_1 = new QLabel(tr("(You may need to restart PulseView for all UI elements to update)"));
255 description_1->setAlignment(Qt::AlignRight);
256 general_layout->addRow(description_1);
257
258 // Style combobox
259 QComboBox *style_cb = new QComboBox();
260 style_cb->addItem(tr("System Default"), "");
261 for (QString& s : QStyleFactory::keys())
262 style_cb->addItem(s, s);
263
264 const QString current_style =
265 settings.value(GlobalSettings::Key_General_Style).toString();
266 if (current_style.isEmpty())
267 style_cb->setCurrentIndex(0);
268 else
269 style_cb->setCurrentIndex(style_cb->findText(current_style));
270
271 connect(style_cb, SIGNAL(currentIndexChanged(int)),
272 this, SLOT(on_general_style_changed(int)));
273 general_layout->addRow(tr("Qt widget style"), style_cb);
274
275 QLabel *description_2 = new QLabel(tr("(Dark themes look best with the Fusion style)"));
276 description_2->setAlignment(Qt::AlignRight);
277 general_layout->addRow(description_2);
278
279 // Misc
280 cb = create_checkbox(GlobalSettings::Key_General_SaveWithSetup,
281 SLOT(on_general_save_with_setup_changed(int)));
282 general_layout->addRow(tr("Save session &setup along with .sr file"), cb);
283
284 cb = create_checkbox(GlobalSettings::Key_General_StartAllSessions,
285 SLOT(on_general_start_all_sessions_changed(int)));
286 general_layout->addRow(tr("Start acquisition for all open sessions when clicking 'Run'"), cb);
287
288
289 return form;
290}
291
292QWidget *Settings::get_view_settings_form(QWidget *parent) const
293{
294 GlobalSettings settings;
295 QCheckBox *cb;
296
297 QWidget *form = new QWidget(parent);
298 QVBoxLayout *form_layout = new QVBoxLayout(form);
299
300 // Trace view settings
301 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
302 form_layout->addWidget(trace_view_group);
303
304 QFormLayout *trace_view_layout = new QFormLayout();
305 trace_view_group->setLayout(trace_view_layout);
306
307 cb = create_checkbox(GlobalSettings::Key_View_ColoredBG,
308 SLOT(on_view_coloredBG_changed(int)));
309 trace_view_layout->addRow(tr("Use colored trace &background"), cb);
310
311 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq,
312 SLOT(on_view_zoomToFitDuringAcq_changed(int)));
313 trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb);
314
315 cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq,
316 SLOT(on_view_zoomToFitAfterAcq_changed(int)));
317 trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb);
318
319 cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime,
320 SLOT(on_view_triggerIsZero_changed(int)));
321 trace_view_layout->addRow(tr("Show time zero at the &trigger"), cb);
322
323 cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling,
324 SLOT(on_view_stickyScrolling_changed(int)));
325 trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb);
326
327 cb = create_checkbox(GlobalSettings::Key_View_AllowVerticalDragging,
328 SLOT(on_view_allowVerticalDragging_changed(int)));
329 trace_view_layout->addRow(tr("Allow &vertical dragging in the view area"), cb);
330
331 cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints,
332 SLOT(on_view_showSamplingPoints_changed(int)));
333 trace_view_layout->addRow(tr("Show data &sampling points"), cb);
334
335 cb = create_checkbox(GlobalSettings::Key_View_FillSignalHighAreas,
336 SLOT(on_view_fillSignalHighAreas_changed(int)));
337 trace_view_layout->addRow(tr("Fill &high areas of logic signals"), cb);
338
339 ColorButton* high_fill_cb = new ColorButton(parent);
340 high_fill_cb->set_color(QColor::fromRgba(
341 settings.value(GlobalSettings::Key_View_FillSignalHighAreaColor).value<uint32_t>()));
342 connect(high_fill_cb, SIGNAL(selected(QColor)),
343 this, SLOT(on_view_fillSignalHighAreaColor_changed(QColor)));
344 trace_view_layout->addRow(tr("Color to fill high areas of logic signals with"), high_fill_cb);
345
346 cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid,
347 SLOT(on_view_showAnalogMinorGrid_changed(int)));
348 trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb);
349
350 cb = create_checkbox(GlobalSettings::Key_View_ShowHoverMarker,
351 SLOT(on_view_showHoverMarker_changed(int)));
352 trace_view_layout->addRow(tr("Highlight mouse cursor using a vertical marker line"), cb);
353
354 QSpinBox *snap_distance_sb = new QSpinBox();
355 snap_distance_sb->setRange(0, 1000);
356 snap_distance_sb->setSuffix(tr(" pixels"));
357 snap_distance_sb->setValue(
358 settings.value(GlobalSettings::Key_View_SnapDistance).toInt());
359 connect(snap_distance_sb, SIGNAL(valueChanged(int)), this,
360 SLOT(on_view_snapDistance_changed(int)));
361 trace_view_layout->addRow(tr("Maximum distance from edges before markers snap to them"), snap_distance_sb);
362
363 ColorButton* cursor_fill_cb = new ColorButton(parent);
364 cursor_fill_cb->set_color(QColor::fromRgba(
365 settings.value(GlobalSettings::Key_View_CursorFillColor).value<uint32_t>()));
366 connect(cursor_fill_cb, SIGNAL(selected(QColor)),
367 this, SLOT(on_view_cursorFillColor_changed(QColor)));
368 trace_view_layout->addRow(tr("Color to fill cursor area with"), cursor_fill_cb);
369
370 QComboBox *thr_disp_mode_cb = new QComboBox();
371 thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None);
372 thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background);
373 thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots);
374 thr_disp_mode_cb->setCurrentIndex(
375 settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt());
376 connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)),
377 this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
378 trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb);
379
380 QSpinBox *default_div_height_sb = new QSpinBox();
381 default_div_height_sb->setRange(20, 1000);
382 default_div_height_sb->setSuffix(tr(" pixels"));
383 default_div_height_sb->setValue(
384 settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt());
385 connect(default_div_height_sb, SIGNAL(valueChanged(int)), this,
386 SLOT(on_view_defaultDivHeight_changed(int)));
387 trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb);
388
389 QSpinBox *default_logic_height_sb = new QSpinBox();
390 default_logic_height_sb->setRange(5, 1000);
391 default_logic_height_sb->setSuffix(tr(" pixels"));
392 default_logic_height_sb->setValue(
393 settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt());
394 connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this,
395 SLOT(on_view_defaultLogicHeight_changed(int)));
396 trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb);
397
398 return form;
399}
400
401QWidget *Settings::get_decoder_settings_form(QWidget *parent)
402{
403#ifdef ENABLE_DECODE
404 GlobalSettings settings;
405 QCheckBox *cb;
406
407 QWidget *form = new QWidget(parent);
408 QVBoxLayout *form_layout = new QVBoxLayout(form);
409
410 // Decoder settings
411 QGroupBox *decoder_group = new QGroupBox(tr("Decoders"));
412 form_layout->addWidget(decoder_group);
413
414 QFormLayout *decoder_layout = new QFormLayout();
415 decoder_group->setLayout(decoder_layout);
416
417 cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable,
418 SLOT(on_dec_initialStateConfigurable_changed(int)));
419 decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb);
420
421 cb = create_checkbox(GlobalSettings::Key_Dec_AlwaysShowAllRows,
422 SLOT(on_dec_alwaysshowallrows_changed(int)));
423 decoder_layout->addRow(tr("Always show all &rows, even if no annotation is visible"), cb);
424
425 // Annotation export settings
426 ann_export_format_ = new QLineEdit();
427 ann_export_format_->setText(
428 settings.value(GlobalSettings::Key_Dec_ExportFormat).toString());
429 connect(ann_export_format_, SIGNAL(textChanged(const QString&)),
430 this, SLOT(on_dec_exportFormat_changed(const QString&)));
431 decoder_layout->addRow(tr("Annotation export format"), ann_export_format_);
432 QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %r: row name; %c: class name"));
433 description_1->setAlignment(Qt::AlignRight);
434 decoder_layout->addRow(description_1);
435 QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts; %q: use quotation marks"));
436 description_2->setAlignment(Qt::AlignRight);
437 decoder_layout->addRow(description_2);
438
439 return form;
440#else
441 (void)parent;
442 return nullptr;
443#endif
444}
445
446QWidget *Settings::get_about_page(QWidget *parent) const
447{
448 Application* a = qobject_cast<Application*>(QApplication::instance());
449
450 QLabel *icon = new QLabel();
451 icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg")));
452
453 // Setup the license field with the project homepage link
454 QLabel *gpl_home_info = new QLabel();
455 gpl_home_info->setText(tr("%1<br /><a href=\"http://%2\">%2</a>").arg(
456 tr("GNU GPL, version 3 or later"),
457 QApplication::organizationDomain()));
458 gpl_home_info->setOpenExternalLinks(true);
459
460 QString s;
461
462 s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
463
464 s.append("<table>");
465
466 s.append("<tr><td colspan=\"2\"><b>" +
467 tr("Versions, libraries and features:") + "</b></td></tr>");
468 for (pair<QString, QString> &entry : a->get_version_info())
469 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
470 .arg(entry.first, entry.second));
471
472 s.append("<tr><td colspan=\"2\"></td></tr>");
473 s.append("<tr><td colspan=\"2\"><b>" +
474 tr("Firmware search paths:") + "</b></td></tr>");
475 for (QString &entry : a->get_fw_path_list())
476 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry));
477
478#ifdef ENABLE_DECODE
479 s.append("<tr><td colspan=\"2\"></td></tr>");
480 s.append("<tr><td colspan=\"2\"><b>" +
481 tr("Protocol decoder search paths:") + "</b></td></tr>");
482 for (QString &entry : a->get_pd_path_list())
483 s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry));
484 s.append(tr("<tr><td colspan=\"2\">(Note: Set environment variable SIGROKDECODE_DIR to add a custom directory)</td></tr>"));
485#endif
486
487 s.append("<tr><td colspan=\"2\"></td></tr>");
488 s.append("<tr><td colspan=\"2\"><b>" +
489 tr("Supported hardware drivers:") + "</b></td></tr>");
490 for (pair<QString, QString> &entry : a->get_driver_list())
491 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
492 .arg(entry.first, entry.second));
493
494 s.append("<tr><td colspan=\"2\"></td></tr>");
495 s.append("<tr><td colspan=\"2\"><b>" +
496 tr("Supported input formats:") + "</b></td></tr>");
497 for (pair<QString, QString> &entry : a->get_input_format_list())
498 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
499 .arg(entry.first, entry.second));
500
501 s.append("<tr><td colspan=\"2\"></td></tr>");
502 s.append("<tr><td colspan=\"2\"><b>" +
503 tr("Supported output formats:") + "</b></td></tr>");
504 for (pair<QString, QString> &entry : a->get_output_format_list())
505 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
506 .arg(entry.first, entry.second));
507
508#ifdef ENABLE_DECODE
509 s.append("<tr><td colspan=\"2\"></td></tr>");
510 s.append("<tr><td colspan=\"2\"><b>" +
511 tr("Supported protocol decoders:") + "</b></td></tr>");
512 for (pair<QString, QString> &entry : a->get_pd_list())
513 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
514 .arg(entry.first, entry.second));
515#endif
516
517 s.append("<tr><td colspan=\"2\"></td></tr>");
518 s.append("<tr><td colspan=\"2\"><b>" +
519 tr("Available Translations:") + "</b></td></tr>");
520 for (const QString& language : a->get_languages()) {
521 if (language == "en")
522 continue;
523
524 const QLocale locale = QLocale(language);
525 const QString desc = locale.languageToString(locale.language());
526 const QString editors = a->get_language_editors(language);
527
528 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>(%2)</td></tr>")
529 .arg(desc, editors));
530 }
531
532 s.append("</table>");
533
534 QTextDocument *supported_doc = new QTextDocument();
535 supported_doc->setHtml(s);
536
537 QTextBrowser *support_list = new QTextBrowser();
538 support_list->setDocument(supported_doc);
539
540 QHBoxLayout *h_layout = new QHBoxLayout();
541 h_layout->setAlignment(Qt::AlignLeft);
542 h_layout->addWidget(icon);
543 h_layout->addWidget(gpl_home_info);
544
545 QVBoxLayout *layout = new QVBoxLayout();
546 layout->addLayout(h_layout);
547 layout->addWidget(support_list);
548
549 QWidget *page = new QWidget(parent);
550 page->setLayout(layout);
551
552 return page;
553}
554
555QWidget *Settings::get_logging_page(QWidget *parent) const
556{
557 GlobalSettings settings;
558
559 // Log level
560 QSpinBox *loglevel_sb = new QSpinBox();
561 loglevel_sb->setMaximum(SR_LOG_SPEW);
562 loglevel_sb->setValue(logging.get_log_level());
563 connect(loglevel_sb, SIGNAL(valueChanged(int)), this,
564 SLOT(on_log_logLevel_changed(int)));
565
566 QHBoxLayout *loglevel_layout = new QHBoxLayout();
567 loglevel_layout->addWidget(new QLabel(tr("Log level:")));
568 loglevel_layout->addWidget(loglevel_sb);
569
570 // Background buffer size
571 QSpinBox *buffersize_sb = new QSpinBox();
572 buffersize_sb->setSuffix(tr(" lines"));
573 buffersize_sb->setMinimum(Logging::MIN_BUFFER_SIZE);
574 buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE);
575 buffersize_sb->setValue(
576 settings.value(GlobalSettings::Key_Log_BufferSize).toInt());
577 connect(buffersize_sb, SIGNAL(valueChanged(int)), this,
578 SLOT(on_log_bufferSize_changed(int)));
579
580 QHBoxLayout *buffersize_layout = new QHBoxLayout();
581 buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:")));
582 buffersize_layout->addWidget(buffersize_sb);
583
584 // Save to file
585 QPushButton *save_log_pb = new QPushButton(
586 QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")),
587 tr("&Save to File"));
588 connect(save_log_pb, SIGNAL(clicked(bool)),
589 this, SLOT(on_log_saveToFile_clicked(bool)));
590
591 // Pop out
592 QPushButton *pop_out_pb = new QPushButton(
593 QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")),
594 tr("&Pop out"));
595 connect(pop_out_pb, SIGNAL(clicked(bool)),
596 this, SLOT(on_log_popOut_clicked(bool)));
597
598 QHBoxLayout *control_layout = new QHBoxLayout();
599 control_layout->addLayout(loglevel_layout);
600 control_layout->addLayout(buffersize_layout);
601 control_layout->addWidget(save_log_pb);
602 control_layout->addWidget(pop_out_pb);
603
604 QVBoxLayout *root_layout = new QVBoxLayout();
605 root_layout->addLayout(control_layout);
606 root_layout->addWidget(log_view_);
607
608 QWidget *page = new QWidget(parent);
609 page->setLayout(root_layout);
610
611 return page;
612}
613
614void Settings::accept()
615{
616 GlobalSettings settings;
617 settings.stop_tracking();
618
619 QDialog::accept();
620}
621
622void Settings::reject()
623{
624 GlobalSettings settings;
625 settings.undo_tracked_changes();
626
627 QDialog::reject();
628}
629
630void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
631{
632 if (!current)
633 current = previous;
634
635 pages->setCurrentIndex(page_list->row(current));
636}
637
638void Settings::on_general_language_changed(const QString &text)
639{
640 GlobalSettings settings;
641 Application* a = qobject_cast<Application*>(QApplication::instance());
642
643 for (const QString& language : a->get_languages()) {
644 QLocale locale = QLocale(language);
645 QString desc = locale.languageToString(locale.language());
646
647 if (text == desc)
648 settings.setValue(GlobalSettings::Key_General_Language, language);
649 }
650}
651
652void Settings::on_general_theme_changed(int value)
653{
654 GlobalSettings settings;
655 settings.setValue(GlobalSettings::Key_General_Theme, value);
656 settings.apply_theme();
657
658 QMessageBox msg(this);
659 msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
660 msg.setIcon(QMessageBox::Question);
661
662 if (settings.current_theme_is_dark()) {
663 msg.setText(tr("You selected a dark theme.\n" \
664 "Should I set the user-adjustable colors to better suit your choice?\n\n" \
665 "Please keep in mind that PulseView may need a restart to display correctly."));
666 if (msg.exec() == QMessageBox::Yes)
667 settings.set_dark_theme_default_colors();
668 } else {
669 msg.setText(tr("You selected a bright theme.\n" \
670 "Should I set the user-adjustable colors to better suit your choice?\n\n" \
671 "Please keep in mind that PulseView may need a restart to display correctly."));
672 if (msg.exec() == QMessageBox::Yes)
673 settings.set_bright_theme_default_colors();
674 }
675}
676
677void Settings::on_general_style_changed(int value)
678{
679 GlobalSettings settings;
680
681 if (value == 0)
682 settings.setValue(GlobalSettings::Key_General_Style, "");
683 else
684 settings.setValue(GlobalSettings::Key_General_Style,
685 QStyleFactory::keys().at(value - 1));
686
687 settings.apply_theme();
688}
689
690void Settings::on_general_save_with_setup_changed(int state)
691{
692 GlobalSettings settings;
693 settings.setValue(GlobalSettings::Key_General_SaveWithSetup, state ? true : false);
694}
695
696void Settings::on_general_start_all_sessions_changed(int state)
697{
698 GlobalSettings settings;
699 settings.setValue(GlobalSettings::Key_General_StartAllSessions, state ? true : false);
700}
701
702void Settings::on_view_zoomToFitDuringAcq_changed(int state)
703{
704 GlobalSettings settings;
705 settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false);
706}
707
708void Settings::on_view_zoomToFitAfterAcq_changed(int state)
709{
710 GlobalSettings settings;
711 settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false);
712}
713
714void Settings::on_view_triggerIsZero_changed(int state)
715{
716 GlobalSettings settings;
717 settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false);
718}
719
720void Settings::on_view_coloredBG_changed(int state)
721{
722 GlobalSettings settings;
723 settings.setValue(GlobalSettings::Key_View_ColoredBG, state ? true : false);
724}
725
726void Settings::on_view_stickyScrolling_changed(int state)
727{
728 GlobalSettings settings;
729 settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
730}
731
732void Settings::on_view_allowVerticalDragging_changed(int state)
733{
734 GlobalSettings settings;
735 settings.setValue(GlobalSettings::Key_View_AllowVerticalDragging, state ? true : false);
736}
737
738void Settings::on_view_showSamplingPoints_changed(int state)
739{
740 GlobalSettings settings;
741 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
742}
743
744void Settings::on_view_fillSignalHighAreas_changed(int state)
745{
746 GlobalSettings settings;
747 settings.setValue(GlobalSettings::Key_View_FillSignalHighAreas, state ? true : false);
748}
749
750void Settings::on_view_fillSignalHighAreaColor_changed(QColor color)
751{
752 GlobalSettings settings;
753 settings.setValue(GlobalSettings::Key_View_FillSignalHighAreaColor, color.rgba());
754}
755
756void Settings::on_view_showAnalogMinorGrid_changed(int state)
757{
758 GlobalSettings settings;
759 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
760}
761
762void Settings::on_view_showHoverMarker_changed(int state)
763{
764 GlobalSettings settings;
765 settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, state ? true : false);
766}
767
768void Settings::on_view_snapDistance_changed(int value)
769{
770 GlobalSettings settings;
771 settings.setValue(GlobalSettings::Key_View_SnapDistance, value);
772}
773
774void Settings::on_view_cursorFillColor_changed(QColor color)
775{
776 GlobalSettings settings;
777 settings.setValue(GlobalSettings::Key_View_CursorFillColor, color.rgba());
778}
779
780void Settings::on_view_conversionThresholdDispMode_changed(int state)
781{
782 GlobalSettings settings;
783 settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state);
784}
785
786void Settings::on_view_defaultDivHeight_changed(int value)
787{
788 GlobalSettings settings;
789 settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value);
790}
791
792void Settings::on_view_defaultLogicHeight_changed(int value)
793{
794 GlobalSettings settings;
795 settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value);
796}
797
798#ifdef ENABLE_DECODE
799void Settings::on_dec_initialStateConfigurable_changed(int state)
800{
801 GlobalSettings settings;
802 settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false);
803}
804
805void Settings::on_dec_exportFormat_changed(const QString &text)
806{
807 GlobalSettings settings;
808 settings.setValue(GlobalSettings::Key_Dec_ExportFormat, text);
809}
810
811void Settings::on_dec_alwaysshowallrows_changed(int state)
812{
813 GlobalSettings settings;
814 settings.setValue(GlobalSettings::Key_Dec_AlwaysShowAllRows, state ? true : false);
815}
816#endif
817
818void Settings::on_log_logLevel_changed(int value)
819{
820 logging.set_log_level(value);
821}
822
823void Settings::on_log_bufferSize_changed(int value)
824{
825 GlobalSettings settings;
826 settings.setValue(GlobalSettings::Key_Log_BufferSize, value);
827}
828
829void Settings::on_log_saveToFile_clicked(bool checked)
830{
831 (void)checked;
832
833 const QString file_name = QFileDialog::getSaveFileName(
834 this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)"));
835
836 if (file_name.isEmpty())
837 return;
838
839 QFile file(file_name);
840 if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
841 QTextStream out_stream(&file);
842 out_stream << log_view_->toPlainText();
843
844 if (out_stream.status() == QTextStream::Ok) {
845 QMessageBox msg(this);
846 msg.setText(tr("Success") + "\n\n" + tr("Log saved to %1.").arg(file_name));
847 msg.setStandardButtons(QMessageBox::Ok);
848 msg.setIcon(QMessageBox::Information);
849 msg.exec();
850
851 return;
852 }
853 }
854
855 QMessageBox msg(this);
856 msg.setText(tr("Error") + "\n\n" + tr("File %1 could not be written to.").arg(file_name));
857 msg.setStandardButtons(QMessageBox::Ok);
858 msg.setIcon(QMessageBox::Warning);
859 msg.exec();
860}
861
862void Settings::on_log_popOut_clicked(bool checked)
863{
864 (void)checked;
865
866 // Create the window as a sub-window so it closes when the main window closes
867 QMainWindow *window = new QMainWindow(nullptr, Qt::SubWindow);
868
869 window->setObjectName(QString::fromUtf8("Log Window"));
870 window->setWindowTitle(tr("%1 Log").arg(PV_TITLE));
871
872 // Use same width/height as the settings dialog
873 window->resize(width(), height());
874
875 window->setCentralWidget(create_log_view());
876 window->show();
877}
878
879} // namespace dialogs
880} // namespace pv