2 * This file is part of the PulseView project.
4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
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.
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.
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/>.
24 #include <QApplication>
26 #include <QDialogButtonBox>
27 #include <QFileDialog>
28 #include <QFormLayout>
30 #include <QHBoxLayout>
32 #include <QMainWindow>
33 #include <QMessageBox>
34 #include <QPushButton>
38 #include <QStyleFactory>
39 #include <QTextBrowser>
40 #include <QTextDocument>
41 #include <QTextStream>
42 #include <QVBoxLayout>
44 #include "settings.hpp"
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"
52 #include <libsigrokcxx/libsigrokcxx.hpp>
55 #include <libsigrokdecode/libsigrokdecode.h>
58 using pv::widgets::ColorButton
;
64 * Special version of a QListView that has the width of the first column as minimum size.
66 * @note Inspired by https://github.com/qt-creator/qt-creator/blob/master/src/plugins/coreplugin/dialogs/settingsdialog.cpp
68 class PageListWidget
: public QListWidget
74 setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::Expanding
);
77 QSize
sizeHint() const final
79 int width
= sizeHintForColumn(0) + frameWidth() * 2 + 5;
80 if (verticalScrollBar()->isVisible())
81 width
+= verticalScrollBar()->width();
82 return QSize(width
, 100);
86 Settings::Settings(DeviceManager
&device_manager
, QWidget
*parent
) :
88 device_manager_(device_manager
)
93 log_view_
= create_log_view();
96 page_list
= new PageListWidget();
97 page_list
->setViewMode(QListView::ListMode
);
98 page_list
->setMovement(QListView::Static
);
99 page_list
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
101 pages
= new QStackedWidget
;
103 page_list
->setCurrentIndex(page_list
->model()->index(0, 0));
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
);
110 QDialogButtonBox
*button_box
= new QDialogButtonBox(
111 QDialogButtonBox::Ok
| QDialogButtonBox::Cancel
);
113 QVBoxLayout
* root_layout
= new QVBoxLayout(this);
114 root_layout
->addLayout(tab_layout
);
115 root_layout
->addWidget(button_box
);
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
*)));
122 // Start to record changes
123 GlobalSettings settings
;
124 settings
.start_tracking();
127 void Settings::create_pages()
130 pages
->addWidget(get_general_settings_form(pages
));
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
);
139 pages
->addWidget(get_view_settings_form(pages
));
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
);
149 pages
->addWidget(get_decoder_settings_form(pages
));
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
);
159 pages
->addWidget(get_about_page(pages
));
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
);
168 pages
->addWidget(get_logging_page(pages
));
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
);
177 QCheckBox
*Settings::create_checkbox(const QString
& key
, const char* slot
) const
179 GlobalSettings settings
;
181 QCheckBox
*cb
= new QCheckBox();
182 cb
->setChecked(settings
.value(key
).toBool());
183 connect(cb
, SIGNAL(stateChanged(int)), this, slot
);
187 QPlainTextEdit
*Settings::create_log_view() const
189 GlobalSettings settings
;
191 QPlainTextEdit
*log_view
= new QPlainTextEdit();
193 log_view
->setReadOnly(true);
194 log_view
->setWordWrapMode(QTextOption::NoWrap
);
195 log_view
->setCenterOnScroll(true);
197 log_view
->appendHtml(logging
.get_log());
198 connect(&logging
, SIGNAL(logged_text(QString
)),
199 log_view
, SLOT(appendHtml(QString
)));
204 QWidget
*Settings::get_general_settings_form(QWidget
*parent
) const
206 GlobalSettings settings
;
209 QWidget
*form
= new QWidget(parent
);
210 QVBoxLayout
*form_layout
= new QVBoxLayout(form
);
213 QGroupBox
*general_group
= new QGroupBox(tr("General"));
214 form_layout
->addWidget(general_group
);
216 QFormLayout
*general_layout
= new QFormLayout();
217 general_group
->setLayout(general_layout
);
219 // Generate language combobox
220 QComboBox
*language_cb
= new QComboBox();
221 Application
* a
= qobject_cast
<Application
*>(QApplication::instance());
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
);
229 if (language
== current_language
) {
230 int index
= language_cb
->findText(desc
, Qt::MatchFixedString
);
231 language_cb
->setCurrentIndex(index
);
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
&)));
238 connect(language_cb
, SIGNAL(currentIndexChanged(const QString
&)),
239 this, SLOT(on_general_language_changed(const QString
&)));
241 general_layout
->addRow(tr("User interface language"), language_cb
);
244 QComboBox
*theme_cb
= new QComboBox();
245 for (const pair
<QString
, QString
>& entry
: Themes
)
246 theme_cb
->addItem(entry
.first
, entry
.second
);
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
);
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
);
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
);
264 const QString current_style
=
265 settings
.value(GlobalSettings::Key_General_Style
).toString();
266 if (current_style
.isEmpty())
267 style_cb
->setCurrentIndex(0);
269 style_cb
->setCurrentIndex(style_cb
->findText(current_style
));
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
);
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
);
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
);
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
);
292 QWidget
*Settings::get_view_settings_form(QWidget
*parent
) const
294 GlobalSettings settings
;
297 QWidget
*form
= new QWidget(parent
);
298 QVBoxLayout
*form_layout
= new QVBoxLayout(form
);
300 // Trace view settings
301 QGroupBox
*trace_view_group
= new QGroupBox(tr("Trace View"));
302 form_layout
->addWidget(trace_view_group
);
304 QFormLayout
*trace_view_layout
= new QFormLayout();
305 trace_view_group
->setLayout(trace_view_layout
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
354 cb
= create_checkbox(GlobalSettings::Key_View_KeepRulerItemSelected
,
355 SLOT(on_view_keepRulerItemSelected_changed(int)));
356 trace_view_layout
->addRow(tr("Keep active item on ruler selected when editing popup is closed"), cb
);
358 QSpinBox
*snap_distance_sb
= new QSpinBox();
359 snap_distance_sb
->setRange(0, 1000);
360 snap_distance_sb
->setSuffix(tr(" pixels"));
361 snap_distance_sb
->setValue(
362 settings
.value(GlobalSettings::Key_View_SnapDistance
).toInt());
363 connect(snap_distance_sb
, SIGNAL(valueChanged(int)), this,
364 SLOT(on_view_snapDistance_changed(int)));
365 trace_view_layout
->addRow(tr("Maximum distance from edges before markers snap to them"), snap_distance_sb
);
367 ColorButton
* cursor_fill_cb
= new ColorButton(parent
);
368 cursor_fill_cb
->set_color(QColor::fromRgba(
369 settings
.value(GlobalSettings::Key_View_CursorFillColor
).value
<uint32_t>()));
370 connect(cursor_fill_cb
, SIGNAL(selected(QColor
)),
371 this, SLOT(on_view_cursorFillColor_changed(QColor
)));
372 trace_view_layout
->addRow(tr("Color to fill cursor area with"), cursor_fill_cb
);
374 QComboBox
*thr_disp_mode_cb
= new QComboBox();
375 thr_disp_mode_cb
->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None
);
376 thr_disp_mode_cb
->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background
);
377 thr_disp_mode_cb
->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots
);
378 thr_disp_mode_cb
->setCurrentIndex(
379 settings
.value(GlobalSettings::Key_View_ConversionThresholdDispMode
).toInt());
380 connect(thr_disp_mode_cb
, SIGNAL(currentIndexChanged(int)),
381 this, SLOT(on_view_conversionThresholdDispMode_changed(int)));
382 trace_view_layout
->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb
);
384 QSpinBox
*default_div_height_sb
= new QSpinBox();
385 default_div_height_sb
->setRange(20, 1000);
386 default_div_height_sb
->setSuffix(tr(" pixels"));
387 default_div_height_sb
->setValue(
388 settings
.value(GlobalSettings::Key_View_DefaultDivHeight
).toInt());
389 connect(default_div_height_sb
, SIGNAL(valueChanged(int)), this,
390 SLOT(on_view_defaultDivHeight_changed(int)));
391 trace_view_layout
->addRow(tr("Default analog trace div height"), default_div_height_sb
);
393 QSpinBox
*default_logic_height_sb
= new QSpinBox();
394 default_logic_height_sb
->setRange(5, 1000);
395 default_logic_height_sb
->setSuffix(tr(" pixels"));
396 default_logic_height_sb
->setValue(
397 settings
.value(GlobalSettings::Key_View_DefaultLogicHeight
).toInt());
398 connect(default_logic_height_sb
, SIGNAL(valueChanged(int)), this,
399 SLOT(on_view_defaultLogicHeight_changed(int)));
400 trace_view_layout
->addRow(tr("Default logic trace height"), default_logic_height_sb
);
405 QWidget
*Settings::get_decoder_settings_form(QWidget
*parent
)
408 GlobalSettings settings
;
411 QWidget
*form
= new QWidget(parent
);
412 QVBoxLayout
*form_layout
= new QVBoxLayout(form
);
415 QGroupBox
*decoder_group
= new QGroupBox(tr("Decoders"));
416 form_layout
->addWidget(decoder_group
);
418 QFormLayout
*decoder_layout
= new QFormLayout();
419 decoder_group
->setLayout(decoder_layout
);
421 cb
= create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable
,
422 SLOT(on_dec_initialStateConfigurable_changed(int)));
423 decoder_layout
->addRow(tr("Allow configuration of &initial signal state"), cb
);
425 cb
= create_checkbox(GlobalSettings::Key_Dec_AlwaysShowAllRows
,
426 SLOT(on_dec_alwaysshowallrows_changed(int)));
427 decoder_layout
->addRow(tr("Always show all &rows, even if no annotation is visible"), cb
);
429 // Annotation export settings
430 ann_export_format_
= new QLineEdit();
431 ann_export_format_
->setText(
432 settings
.value(GlobalSettings::Key_Dec_ExportFormat
).toString());
433 connect(ann_export_format_
, SIGNAL(textChanged(const QString
&)),
434 this, SLOT(on_dec_exportFormat_changed(const QString
&)));
435 decoder_layout
->addRow(tr("Annotation export format"), ann_export_format_
);
436 QLabel
*description_1
= new QLabel(tr("%s = sample range; %d: decoder name; %r: row name; %c: class name"));
437 description_1
->setAlignment(Qt::AlignRight
);
438 decoder_layout
->addRow(description_1
);
439 QLabel
*description_2
= new QLabel(tr("%1: longest annotation text; %a: all annotation texts; %q: use quotation marks"));
440 description_2
->setAlignment(Qt::AlignRight
);
441 decoder_layout
->addRow(description_2
);
450 QWidget
*Settings::get_about_page(QWidget
*parent
) const
452 Application
* a
= qobject_cast
<Application
*>(QApplication::instance());
454 QLabel
*icon
= new QLabel();
455 icon
->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg")));
457 // Setup the license field with the project homepage link
458 QLabel
*gpl_home_info
= new QLabel();
459 gpl_home_info
->setText(tr("%1<br /><a href=\"http://%2\">%2</a>").arg(
460 tr("GNU GPL, version 3 or later"),
461 QApplication::organizationDomain()));
462 gpl_home_info
->setOpenExternalLinks(true);
466 s
.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
470 s
.append("<tr><td colspan=\"2\"><b>" +
471 tr("Versions, libraries and features:") + "</b></td></tr>");
472 for (pair
<QString
, QString
> &entry
: a
->get_version_info())
473 s
.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
474 .arg(entry
.first
, entry
.second
));
476 s
.append("<tr><td colspan=\"2\"></td></tr>");
477 s
.append("<tr><td colspan=\"2\"><b>" +
478 tr("Firmware search paths:") + "</b></td></tr>");
479 for (QString
&entry
: a
->get_fw_path_list())
480 s
.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry
));
483 s
.append("<tr><td colspan=\"2\"></td></tr>");
484 s
.append("<tr><td colspan=\"2\"><b>" +
485 tr("Protocol decoder search paths:") + "</b></td></tr>");
486 for (QString
&entry
: a
->get_pd_path_list())
487 s
.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry
));
488 s
.append(tr("<tr><td colspan=\"2\">(Note: Set environment variable SIGROKDECODE_DIR to add a custom directory)</td></tr>"));
491 s
.append("<tr><td colspan=\"2\"></td></tr>");
492 s
.append("<tr><td colspan=\"2\"><b>" +
493 tr("Supported hardware drivers:") + "</b></td></tr>");
494 for (pair
<QString
, QString
> &entry
: a
->get_driver_list())
495 s
.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
496 .arg(entry
.first
, entry
.second
));
498 s
.append("<tr><td colspan=\"2\"></td></tr>");
499 s
.append("<tr><td colspan=\"2\"><b>" +
500 tr("Supported input formats:") + "</b></td></tr>");
501 for (pair
<QString
, QString
> &entry
: a
->get_input_format_list())
502 s
.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
503 .arg(entry
.first
, entry
.second
));
505 s
.append("<tr><td colspan=\"2\"></td></tr>");
506 s
.append("<tr><td colspan=\"2\"><b>" +
507 tr("Supported output formats:") + "</b></td></tr>");
508 for (pair
<QString
, QString
> &entry
: a
->get_output_format_list())
509 s
.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
510 .arg(entry
.first
, entry
.second
));
513 s
.append("<tr><td colspan=\"2\"></td></tr>");
514 s
.append("<tr><td colspan=\"2\"><b>" +
515 tr("Supported protocol decoders:") + "</b></td></tr>");
516 for (pair
<QString
, QString
> &entry
: a
->get_pd_list())
517 s
.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
518 .arg(entry
.first
, entry
.second
));
521 s
.append("<tr><td colspan=\"2\"></td></tr>");
522 s
.append("<tr><td colspan=\"2\"><b>" +
523 tr("Available Translations:") + "</b></td></tr>");
524 for (const QString
& language
: a
->get_languages()) {
525 if (language
== "en")
528 const QLocale locale
= QLocale(language
);
529 const QString desc
= locale
.languageToString(locale
.language());
530 const QString editors
= a
->get_language_editors(language
);
532 s
.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>(%2)</td></tr>")
533 .arg(desc
, editors
));
536 s
.append("</table>");
538 QTextDocument
*supported_doc
= new QTextDocument();
539 supported_doc
->setHtml(s
);
541 QTextBrowser
*support_list
= new QTextBrowser();
542 support_list
->setDocument(supported_doc
);
544 QHBoxLayout
*h_layout
= new QHBoxLayout();
545 h_layout
->setAlignment(Qt::AlignLeft
);
546 h_layout
->addWidget(icon
);
547 h_layout
->addWidget(gpl_home_info
);
549 QVBoxLayout
*layout
= new QVBoxLayout();
550 layout
->addLayout(h_layout
);
551 layout
->addWidget(support_list
);
553 QWidget
*page
= new QWidget(parent
);
554 page
->setLayout(layout
);
559 QWidget
*Settings::get_logging_page(QWidget
*parent
) const
561 GlobalSettings settings
;
564 QSpinBox
*loglevel_sb
= new QSpinBox();
565 loglevel_sb
->setMaximum(SR_LOG_SPEW
);
566 loglevel_sb
->setValue(logging
.get_log_level());
567 connect(loglevel_sb
, SIGNAL(valueChanged(int)), this,
568 SLOT(on_log_logLevel_changed(int)));
570 QHBoxLayout
*loglevel_layout
= new QHBoxLayout();
571 loglevel_layout
->addWidget(new QLabel(tr("Log level:")));
572 loglevel_layout
->addWidget(loglevel_sb
);
574 // Background buffer size
575 QSpinBox
*buffersize_sb
= new QSpinBox();
576 buffersize_sb
->setSuffix(tr(" lines"));
577 buffersize_sb
->setMinimum(Logging::MIN_BUFFER_SIZE
);
578 buffersize_sb
->setMaximum(Logging::MAX_BUFFER_SIZE
);
579 buffersize_sb
->setValue(
580 settings
.value(GlobalSettings::Key_Log_BufferSize
).toInt());
581 connect(buffersize_sb
, SIGNAL(valueChanged(int)), this,
582 SLOT(on_log_bufferSize_changed(int)));
584 QHBoxLayout
*buffersize_layout
= new QHBoxLayout();
585 buffersize_layout
->addWidget(new QLabel(tr("Length of background buffer:")));
586 buffersize_layout
->addWidget(buffersize_sb
);
589 QPushButton
*save_log_pb
= new QPushButton(
590 QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")),
591 tr("&Save to File"));
592 connect(save_log_pb
, SIGNAL(clicked(bool)),
593 this, SLOT(on_log_saveToFile_clicked(bool)));
596 QPushButton
*pop_out_pb
= new QPushButton(
597 QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")),
599 connect(pop_out_pb
, SIGNAL(clicked(bool)),
600 this, SLOT(on_log_popOut_clicked(bool)));
602 QHBoxLayout
*control_layout
= new QHBoxLayout();
603 control_layout
->addLayout(loglevel_layout
);
604 control_layout
->addLayout(buffersize_layout
);
605 control_layout
->addWidget(save_log_pb
);
606 control_layout
->addWidget(pop_out_pb
);
608 QVBoxLayout
*root_layout
= new QVBoxLayout();
609 root_layout
->addLayout(control_layout
);
610 root_layout
->addWidget(log_view_
);
612 QWidget
*page
= new QWidget(parent
);
613 page
->setLayout(root_layout
);
618 void Settings::accept()
620 GlobalSettings settings
;
621 settings
.stop_tracking();
626 void Settings::reject()
628 GlobalSettings settings
;
629 settings
.undo_tracked_changes();
634 void Settings::on_page_changed(QListWidgetItem
*current
, QListWidgetItem
*previous
)
639 pages
->setCurrentIndex(page_list
->row(current
));
642 void Settings::on_general_language_changed(const QString
&text
)
644 GlobalSettings settings
;
645 Application
* a
= qobject_cast
<Application
*>(QApplication::instance());
647 for (const QString
& language
: a
->get_languages()) {
648 QLocale locale
= QLocale(language
);
649 QString desc
= locale
.languageToString(locale
.language());
652 settings
.setValue(GlobalSettings::Key_General_Language
, language
);
656 void Settings::on_general_theme_changed(int value
)
658 GlobalSettings settings
;
659 settings
.setValue(GlobalSettings::Key_General_Theme
, value
);
660 settings
.apply_theme();
662 QMessageBox
msg(this);
663 msg
.setStandardButtons(QMessageBox::Yes
| QMessageBox::No
);
664 msg
.setIcon(QMessageBox::Question
);
666 if (settings
.current_theme_is_dark()) {
667 msg
.setText(tr("You selected a dark theme.\n" \
668 "Should I set the user-adjustable colors to better suit your choice?\n\n" \
669 "Please keep in mind that PulseView may need a restart to display correctly."));
670 if (msg
.exec() == QMessageBox::Yes
)
671 settings
.set_dark_theme_default_colors();
673 msg
.setText(tr("You selected a bright theme.\n" \
674 "Should I set the user-adjustable colors to better suit your choice?\n\n" \
675 "Please keep in mind that PulseView may need a restart to display correctly."));
676 if (msg
.exec() == QMessageBox::Yes
)
677 settings
.set_bright_theme_default_colors();
681 void Settings::on_general_style_changed(int value
)
683 GlobalSettings settings
;
686 settings
.setValue(GlobalSettings::Key_General_Style
, "");
688 settings
.setValue(GlobalSettings::Key_General_Style
,
689 QStyleFactory::keys().at(value
- 1));
691 settings
.apply_theme();
694 void Settings::on_general_save_with_setup_changed(int state
)
696 GlobalSettings settings
;
697 settings
.setValue(GlobalSettings::Key_General_SaveWithSetup
, state
? true : false);
700 void Settings::on_general_start_all_sessions_changed(int state
)
702 GlobalSettings settings
;
703 settings
.setValue(GlobalSettings::Key_General_StartAllSessions
, state
? true : false);
706 void Settings::on_view_zoomToFitDuringAcq_changed(int state
)
708 GlobalSettings settings
;
709 settings
.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq
, state
? true : false);
712 void Settings::on_view_zoomToFitAfterAcq_changed(int state
)
714 GlobalSettings settings
;
715 settings
.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq
, state
? true : false);
718 void Settings::on_view_triggerIsZero_changed(int state
)
720 GlobalSettings settings
;
721 settings
.setValue(GlobalSettings::Key_View_TriggerIsZeroTime
, state
? true : false);
724 void Settings::on_view_coloredBG_changed(int state
)
726 GlobalSettings settings
;
727 settings
.setValue(GlobalSettings::Key_View_ColoredBG
, state
? true : false);
730 void Settings::on_view_stickyScrolling_changed(int state
)
732 GlobalSettings settings
;
733 settings
.setValue(GlobalSettings::Key_View_StickyScrolling
, state
? true : false);
736 void Settings::on_view_allowVerticalDragging_changed(int state
)
738 GlobalSettings settings
;
739 settings
.setValue(GlobalSettings::Key_View_AllowVerticalDragging
, state
? true : false);
742 void Settings::on_view_showSamplingPoints_changed(int state
)
744 GlobalSettings settings
;
745 settings
.setValue(GlobalSettings::Key_View_ShowSamplingPoints
, state
? true : false);
748 void Settings::on_view_fillSignalHighAreas_changed(int state
)
750 GlobalSettings settings
;
751 settings
.setValue(GlobalSettings::Key_View_FillSignalHighAreas
, state
? true : false);
754 void Settings::on_view_fillSignalHighAreaColor_changed(QColor color
)
756 GlobalSettings settings
;
757 settings
.setValue(GlobalSettings::Key_View_FillSignalHighAreaColor
, color
.rgba());
760 void Settings::on_view_showAnalogMinorGrid_changed(int state
)
762 GlobalSettings settings
;
763 settings
.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid
, state
? true : false);
766 void Settings::on_view_showHoverMarker_changed(int state
)
768 GlobalSettings settings
;
769 settings
.setValue(GlobalSettings::Key_View_ShowHoverMarker
, state
? true : false);
772 void Settings::on_view_keepRulerItemSelected_changed(int state
)
774 GlobalSettings settings
;
775 settings
.setValue(GlobalSettings::Key_View_KeepRulerItemSelected
, state
? true : false);
778 void Settings::on_view_snapDistance_changed(int value
)
780 GlobalSettings settings
;
781 settings
.setValue(GlobalSettings::Key_View_SnapDistance
, value
);
784 void Settings::on_view_cursorFillColor_changed(QColor color
)
786 GlobalSettings settings
;
787 settings
.setValue(GlobalSettings::Key_View_CursorFillColor
, color
.rgba());
790 void Settings::on_view_conversionThresholdDispMode_changed(int state
)
792 GlobalSettings settings
;
793 settings
.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode
, state
);
796 void Settings::on_view_defaultDivHeight_changed(int value
)
798 GlobalSettings settings
;
799 settings
.setValue(GlobalSettings::Key_View_DefaultDivHeight
, value
);
802 void Settings::on_view_defaultLogicHeight_changed(int value
)
804 GlobalSettings settings
;
805 settings
.setValue(GlobalSettings::Key_View_DefaultLogicHeight
, value
);
809 void Settings::on_dec_initialStateConfigurable_changed(int state
)
811 GlobalSettings settings
;
812 settings
.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable
, state
? true : false);
815 void Settings::on_dec_exportFormat_changed(const QString
&text
)
817 GlobalSettings settings
;
818 settings
.setValue(GlobalSettings::Key_Dec_ExportFormat
, text
);
821 void Settings::on_dec_alwaysshowallrows_changed(int state
)
823 GlobalSettings settings
;
824 settings
.setValue(GlobalSettings::Key_Dec_AlwaysShowAllRows
, state
? true : false);
828 void Settings::on_log_logLevel_changed(int value
)
830 logging
.set_log_level(value
);
833 void Settings::on_log_bufferSize_changed(int value
)
835 GlobalSettings settings
;
836 settings
.setValue(GlobalSettings::Key_Log_BufferSize
, value
);
839 void Settings::on_log_saveToFile_clicked(bool checked
)
843 const QString file_name
= QFileDialog::getSaveFileName(
844 this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)"));
846 if (file_name
.isEmpty())
849 QFile
file(file_name
);
850 if (file
.open(QIODevice::WriteOnly
| QIODevice::Truncate
| QIODevice::Text
)) {
851 QTextStream
out_stream(&file
);
852 out_stream
<< log_view_
->toPlainText();
854 if (out_stream
.status() == QTextStream::Ok
) {
855 QMessageBox
msg(this);
856 msg
.setText(tr("Success") + "\n\n" + tr("Log saved to %1.").arg(file_name
));
857 msg
.setStandardButtons(QMessageBox::Ok
);
858 msg
.setIcon(QMessageBox::Information
);
865 QMessageBox
msg(this);
866 msg
.setText(tr("Error") + "\n\n" + tr("File %1 could not be written to.").arg(file_name
));
867 msg
.setStandardButtons(QMessageBox::Ok
);
868 msg
.setIcon(QMessageBox::Warning
);
872 void Settings::on_log_popOut_clicked(bool checked
)
876 // Create the window as a sub-window so it closes when the main window closes
877 QMainWindow
*window
= new QMainWindow(nullptr, Qt::SubWindow
);
879 window
->setObjectName(QString::fromUtf8("Log Window"));
880 window
->setWindowTitle(tr("%1 Log").arg(PV_TITLE
));
882 // Use same width/height as the settings dialog
883 window
->resize(width(), height());
885 window
->setCentralWidget(create_log_view());
889 } // namespace dialogs