]>
Commit | Line | Data |
---|---|---|
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 <QTextBrowser> | |
39 | #include <QTextDocument> | |
40 | #include <QTextStream> | |
41 | #include <QVBoxLayout> | |
42 | ||
43 | #include "settings.hpp" | |
44 | ||
45 | #include "pv/application.hpp" | |
46 | #include "pv/devicemanager.hpp" | |
47 | #include "pv/globalsettings.hpp" | |
48 | #include "pv/logging.hpp" | |
49 | ||
50 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
51 | ||
52 | #ifdef ENABLE_DECODE | |
53 | #include <libsigrokdecode/libsigrokdecode.h> | |
54 | #endif | |
55 | ||
56 | using std::shared_ptr; | |
57 | ||
58 | namespace pv { | |
59 | namespace dialogs { | |
60 | ||
61 | /** | |
62 | * Special version of a QListView that has the width of the first column as minimum size. | |
63 | * | |
64 | * @note Inspired by https://github.com/qt-creator/qt-creator/blob/master/src/plugins/coreplugin/dialogs/settingsdialog.cpp | |
65 | */ | |
66 | class PageListWidget: public QListWidget | |
67 | { | |
68 | public: | |
69 | PageListWidget() : | |
70 | QListWidget() | |
71 | { | |
72 | setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); | |
73 | } | |
74 | ||
75 | QSize sizeHint() const final | |
76 | { | |
77 | int width = sizeHintForColumn(0) + frameWidth() * 2 + 5; | |
78 | if (verticalScrollBar()->isVisible()) | |
79 | width += verticalScrollBar()->width(); | |
80 | return QSize(width, 100); | |
81 | } | |
82 | }; | |
83 | ||
84 | Settings::Settings(DeviceManager &device_manager, QWidget *parent) : | |
85 | QDialog(parent, nullptr), | |
86 | device_manager_(device_manager) | |
87 | { | |
88 | resize(600, 400); | |
89 | ||
90 | // Create log view | |
91 | log_view_ = create_log_view(); | |
92 | ||
93 | // Create pages | |
94 | page_list = new PageListWidget(); | |
95 | page_list->setViewMode(QListView::ListMode); | |
96 | page_list->setMovement(QListView::Static); | |
97 | page_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
98 | ||
99 | pages = new QStackedWidget; | |
100 | create_pages(); | |
101 | page_list->setCurrentIndex(page_list->model()->index(0, 0)); | |
102 | ||
103 | // Create the rest of the dialog | |
104 | QHBoxLayout *tab_layout = new QHBoxLayout; | |
105 | tab_layout->addWidget(page_list); | |
106 | tab_layout->addWidget(pages, Qt::AlignLeft); | |
107 | ||
108 | QDialogButtonBox *button_box = new QDialogButtonBox( | |
109 | QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | |
110 | ||
111 | QVBoxLayout* root_layout = new QVBoxLayout(this); | |
112 | root_layout->addLayout(tab_layout); | |
113 | root_layout->addWidget(button_box); | |
114 | ||
115 | connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); | |
116 | connect(button_box, SIGNAL(rejected()), this, SLOT(reject())); | |
117 | connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), | |
118 | this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*))); | |
119 | ||
120 | // Start to record changes | |
121 | GlobalSettings settings; | |
122 | settings.start_tracking(); | |
123 | } | |
124 | ||
125 | void Settings::create_pages() | |
126 | { | |
127 | // View page | |
128 | pages->addWidget(get_view_settings_form(pages)); | |
129 | ||
130 | QListWidgetItem *viewButton = new QListWidgetItem(page_list); | |
131 | viewButton->setIcon(QIcon(":/icons/settings-views.svg")); | |
132 | viewButton->setText(tr("Views")); | |
133 | viewButton->setTextAlignment(Qt::AlignVCenter); | |
134 | viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
135 | ||
136 | #ifdef ENABLE_DECODE | |
137 | // Decoder page | |
138 | pages->addWidget(get_decoder_settings_form(pages)); | |
139 | ||
140 | QListWidgetItem *decoderButton = new QListWidgetItem(page_list); | |
141 | decoderButton->setIcon(QIcon(":/icons/add-decoder.svg")); | |
142 | decoderButton->setText(tr("Decoders")); | |
143 | decoderButton->setTextAlignment(Qt::AlignVCenter); | |
144 | decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
145 | #endif | |
146 | ||
147 | // About page | |
148 | pages->addWidget(get_about_page(pages)); | |
149 | ||
150 | QListWidgetItem *aboutButton = new QListWidgetItem(page_list); | |
151 | aboutButton->setIcon(QIcon(":/icons/information.svg")); | |
152 | aboutButton->setText(tr("About")); | |
153 | aboutButton->setTextAlignment(Qt::AlignVCenter); | |
154 | aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
155 | ||
156 | // Logging page | |
157 | pages->addWidget(get_logging_page(pages)); | |
158 | ||
159 | QListWidgetItem *loggingButton = new QListWidgetItem(page_list); | |
160 | loggingButton->setIcon(QIcon(":/icons/information.svg")); | |
161 | loggingButton->setText(tr("Logging")); | |
162 | loggingButton->setTextAlignment(Qt::AlignVCenter); | |
163 | loggingButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
164 | } | |
165 | ||
166 | QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const | |
167 | { | |
168 | GlobalSettings settings; | |
169 | ||
170 | QCheckBox *cb = new QCheckBox(); | |
171 | cb->setChecked(settings.value(key).toBool()); | |
172 | connect(cb, SIGNAL(stateChanged(int)), this, slot); | |
173 | return cb; | |
174 | } | |
175 | ||
176 | QPlainTextEdit *Settings::create_log_view() const | |
177 | { | |
178 | GlobalSettings settings; | |
179 | ||
180 | QPlainTextEdit *log_view = new QPlainTextEdit(); | |
181 | ||
182 | log_view->setReadOnly(true); | |
183 | log_view->setWordWrapMode(QTextOption::NoWrap); | |
184 | log_view->setCenterOnScroll(true); | |
185 | ||
186 | log_view->appendHtml(logging.get_log()); | |
187 | connect(&logging, SIGNAL(logged_text(QString)), | |
188 | log_view, SLOT(appendHtml(QString))); | |
189 | ||
190 | return log_view; | |
191 | } | |
192 | ||
193 | QWidget *Settings::get_view_settings_form(QWidget *parent) const | |
194 | { | |
195 | GlobalSettings settings; | |
196 | QCheckBox *cb; | |
197 | ||
198 | QWidget *form = new QWidget(parent); | |
199 | QVBoxLayout *form_layout = new QVBoxLayout(form); | |
200 | ||
201 | // Trace view settings | |
202 | QGroupBox *trace_view_group = new QGroupBox(tr("Trace View")); | |
203 | form_layout->addWidget(trace_view_group); | |
204 | ||
205 | QFormLayout *trace_view_layout = new QFormLayout(); | |
206 | trace_view_group->setLayout(trace_view_layout); | |
207 | ||
208 | cb = create_checkbox(GlobalSettings::Key_View_ColoredBG, | |
209 | SLOT(on_view_coloredBG_changed(int))); | |
210 | trace_view_layout->addRow(tr("Use colored trace &background"), cb); | |
211 | ||
212 | cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq, | |
213 | SLOT(on_view_zoomToFitDuringAcq_changed(int))); | |
214 | trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb); | |
215 | ||
216 | cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq, | |
217 | SLOT(on_view_zoomToFitAfterAcq_changed(int))); | |
218 | trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb); | |
219 | ||
220 | cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime, | |
221 | SLOT(on_view_triggerIsZero_changed(int))); | |
222 | trace_view_layout->addRow(tr("Show time zero at the trigger"), cb); | |
223 | ||
224 | cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling, | |
225 | SLOT(on_view_stickyScrolling_changed(int))); | |
226 | trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb); | |
227 | ||
228 | cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints, | |
229 | SLOT(on_view_showSamplingPoints_changed(int))); | |
230 | trace_view_layout->addRow(tr("Show data &sampling points"), cb); | |
231 | ||
232 | cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid, | |
233 | SLOT(on_view_showAnalogMinorGrid_changed(int))); | |
234 | trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb); | |
235 | ||
236 | cb = create_checkbox(GlobalSettings::Key_View_ShowHoverMarker, | |
237 | SLOT(on_view_showHoverMarker_changed(int))); | |
238 | trace_view_layout->addRow(tr("Highlight mouse cursor using a vertical marker line"), cb); | |
239 | ||
240 | QSpinBox *snap_distance_sb = new QSpinBox(); | |
241 | snap_distance_sb->setRange(0, 1000); | |
242 | snap_distance_sb->setSuffix(tr(" pixels")); | |
243 | snap_distance_sb->setValue( | |
244 | settings.value(GlobalSettings::Key_View_SnapDistance).toInt()); | |
245 | connect(snap_distance_sb, SIGNAL(valueChanged(int)), this, | |
246 | SLOT(on_view_snapDistance_changed(int))); | |
247 | trace_view_layout->addRow(tr("Maximum distance from edges before cursors snap to them"), snap_distance_sb); | |
248 | ||
249 | QComboBox *thr_disp_mode_cb = new QComboBox(); | |
250 | thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None); | |
251 | thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background); | |
252 | thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots); | |
253 | thr_disp_mode_cb->setCurrentIndex( | |
254 | settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt()); | |
255 | connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)), | |
256 | this, SLOT(on_view_conversionThresholdDispMode_changed(int))); | |
257 | trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb); | |
258 | ||
259 | QSpinBox *default_div_height_sb = new QSpinBox(); | |
260 | default_div_height_sb->setRange(20, 1000); | |
261 | default_div_height_sb->setSuffix(tr(" pixels")); | |
262 | default_div_height_sb->setValue( | |
263 | settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt()); | |
264 | connect(default_div_height_sb, SIGNAL(valueChanged(int)), this, | |
265 | SLOT(on_view_defaultDivHeight_changed(int))); | |
266 | trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb); | |
267 | ||
268 | QSpinBox *default_logic_height_sb = new QSpinBox(); | |
269 | default_logic_height_sb->setRange(5, 1000); | |
270 | default_logic_height_sb->setSuffix(tr(" pixels")); | |
271 | default_logic_height_sb->setValue( | |
272 | settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt()); | |
273 | connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this, | |
274 | SLOT(on_view_defaultLogicHeight_changed(int))); | |
275 | trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb); | |
276 | ||
277 | return form; | |
278 | } | |
279 | ||
280 | QWidget *Settings::get_decoder_settings_form(QWidget *parent) | |
281 | { | |
282 | #ifdef ENABLE_DECODE | |
283 | GlobalSettings settings; | |
284 | QCheckBox *cb; | |
285 | ||
286 | QWidget *form = new QWidget(parent); | |
287 | QVBoxLayout *form_layout = new QVBoxLayout(form); | |
288 | ||
289 | // Decoder settings | |
290 | QGroupBox *decoder_group = new QGroupBox(tr("Decoders")); | |
291 | form_layout->addWidget(decoder_group); | |
292 | ||
293 | QFormLayout *decoder_layout = new QFormLayout(); | |
294 | decoder_group->setLayout(decoder_layout); | |
295 | ||
296 | cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable, | |
297 | SLOT(on_dec_initialStateConfigurable_changed(int))); | |
298 | decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb); | |
299 | ||
300 | // Annotation export settings | |
301 | ann_export_format_ = new QLineEdit(); | |
302 | ann_export_format_->setText( | |
303 | settings.value(GlobalSettings::Key_Dec_ExportFormat).toString()); | |
304 | connect(ann_export_format_, SIGNAL(textChanged(const QString&)), | |
305 | this, SLOT(on_dec_exportFormat_changed(const QString&))); | |
306 | decoder_layout->addRow(tr("Annotation export format"), ann_export_format_); | |
307 | QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %c: row name; %q: use quotations marks")); | |
308 | description_1->setAlignment(Qt::AlignRight); | |
309 | decoder_layout->addRow(description_1); | |
310 | QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts")); | |
311 | description_2->setAlignment(Qt::AlignRight); | |
312 | decoder_layout->addRow(description_2); | |
313 | ||
314 | return form; | |
315 | #else | |
316 | (void)parent; | |
317 | return nullptr; | |
318 | #endif | |
319 | } | |
320 | ||
321 | QWidget *Settings::get_about_page(QWidget *parent) const | |
322 | { | |
323 | Application* a = qobject_cast<Application*>(QApplication::instance()); | |
324 | ||
325 | QLabel *icon = new QLabel(); | |
326 | icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg"))); | |
327 | ||
328 | // Setup the license field with the project homepage link | |
329 | QLabel *gpl_home_info = new QLabel(); | |
330 | gpl_home_info->setText(tr("%1<br /><a href=\"http://%2\">%2</a>").arg( | |
331 | tr("GNU GPL, version 3 or later"), | |
332 | QApplication::organizationDomain())); | |
333 | gpl_home_info->setOpenExternalLinks(true); | |
334 | ||
335 | QString s; | |
336 | ||
337 | s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>"); | |
338 | ||
339 | s.append("<table>"); | |
340 | ||
341 | s.append("<tr><td colspan=\"2\"><b>" + | |
342 | tr("Versions, libraries and features:") + "</b></td></tr>"); | |
343 | for (pair<QString, QString> &entry : a->get_version_info()) | |
344 | s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>") | |
345 | .arg(entry.first, entry.second)); | |
346 | ||
347 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
348 | s.append("<tr><td colspan=\"2\"><b>" + | |
349 | tr("Firmware search paths:") + "</b></td></tr>"); | |
350 | for (QString &entry : a->get_fw_path_list()) | |
351 | s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry)); | |
352 | ||
353 | #ifdef ENABLE_DECODE | |
354 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
355 | s.append("<tr><td colspan=\"2\"><b>" + | |
356 | tr("Protocol decoder search paths:") + "</b></td></tr>"); | |
357 | for (QString &entry : a->get_pd_path_list()) | |
358 | s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry)); | |
359 | #endif | |
360 | ||
361 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
362 | s.append("<tr><td colspan=\"2\"><b>" + | |
363 | tr("Supported hardware drivers:") + "</b></td></tr>"); | |
364 | for (pair<QString, QString> &entry : a->get_driver_list()) | |
365 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") | |
366 | .arg(entry.first, entry.second)); | |
367 | ||
368 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
369 | s.append("<tr><td colspan=\"2\"><b>" + | |
370 | tr("Supported input formats:") + "</b></td></tr>"); | |
371 | for (pair<QString, QString> &entry : a->get_input_format_list()) | |
372 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") | |
373 | .arg(entry.first, entry.second)); | |
374 | ||
375 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
376 | s.append("<tr><td colspan=\"2\"><b>" + | |
377 | tr("Supported output formats:") + "</b></td></tr>"); | |
378 | for (pair<QString, QString> &entry : a->get_output_format_list()) | |
379 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") | |
380 | .arg(entry.first, entry.second)); | |
381 | ||
382 | #ifdef ENABLE_DECODE | |
383 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
384 | s.append("<tr><td colspan=\"2\"><b>" + | |
385 | tr("Supported protocol decoders:") + "</b></td></tr>"); | |
386 | for (pair<QString, QString> &entry : a->get_pd_list()) | |
387 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") | |
388 | .arg(entry.first, entry.second)); | |
389 | #endif | |
390 | ||
391 | s.append("</table>"); | |
392 | ||
393 | QTextDocument *supported_doc = new QTextDocument(); | |
394 | supported_doc->setHtml(s); | |
395 | ||
396 | QTextBrowser *support_list = new QTextBrowser(); | |
397 | support_list->setDocument(supported_doc); | |
398 | ||
399 | QHBoxLayout *h_layout = new QHBoxLayout(); | |
400 | h_layout->setAlignment(Qt::AlignLeft); | |
401 | h_layout->addWidget(icon); | |
402 | h_layout->addWidget(gpl_home_info); | |
403 | ||
404 | QVBoxLayout *layout = new QVBoxLayout(); | |
405 | layout->addLayout(h_layout); | |
406 | layout->addWidget(support_list); | |
407 | ||
408 | QWidget *page = new QWidget(parent); | |
409 | page->setLayout(layout); | |
410 | ||
411 | return page; | |
412 | } | |
413 | ||
414 | QWidget *Settings::get_logging_page(QWidget *parent) const | |
415 | { | |
416 | GlobalSettings settings; | |
417 | ||
418 | // Log level | |
419 | QSpinBox *loglevel_sb = new QSpinBox(); | |
420 | loglevel_sb->setMaximum(SR_LOG_SPEW); | |
421 | loglevel_sb->setValue(logging.get_log_level()); | |
422 | connect(loglevel_sb, SIGNAL(valueChanged(int)), this, | |
423 | SLOT(on_log_logLevel_changed(int))); | |
424 | ||
425 | QHBoxLayout *loglevel_layout = new QHBoxLayout(); | |
426 | loglevel_layout->addWidget(new QLabel(tr("Log level:"))); | |
427 | loglevel_layout->addWidget(loglevel_sb); | |
428 | ||
429 | // Background buffer size | |
430 | QSpinBox *buffersize_sb = new QSpinBox(); | |
431 | buffersize_sb->setSuffix(tr(" lines")); | |
432 | buffersize_sb->setMinimum(Logging::MIN_BUFFER_SIZE); | |
433 | buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE); | |
434 | buffersize_sb->setValue( | |
435 | settings.value(GlobalSettings::Key_Log_BufferSize).toInt()); | |
436 | connect(buffersize_sb, SIGNAL(valueChanged(int)), this, | |
437 | SLOT(on_log_bufferSize_changed(int))); | |
438 | ||
439 | QHBoxLayout *buffersize_layout = new QHBoxLayout(); | |
440 | buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:"))); | |
441 | buffersize_layout->addWidget(buffersize_sb); | |
442 | ||
443 | // Save to file | |
444 | QPushButton *save_log_pb = new QPushButton( | |
445 | QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")), | |
446 | tr("&Save to File")); | |
447 | connect(save_log_pb, SIGNAL(clicked(bool)), | |
448 | this, SLOT(on_log_saveToFile_clicked(bool))); | |
449 | ||
450 | // Pop out | |
451 | QPushButton *pop_out_pb = new QPushButton( | |
452 | QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")), | |
453 | tr("&Pop out")); | |
454 | connect(pop_out_pb, SIGNAL(clicked(bool)), | |
455 | this, SLOT(on_log_popOut_clicked(bool))); | |
456 | ||
457 | QHBoxLayout *control_layout = new QHBoxLayout(); | |
458 | control_layout->addLayout(loglevel_layout); | |
459 | control_layout->addLayout(buffersize_layout); | |
460 | control_layout->addWidget(save_log_pb); | |
461 | control_layout->addWidget(pop_out_pb); | |
462 | ||
463 | QVBoxLayout *root_layout = new QVBoxLayout(); | |
464 | root_layout->addLayout(control_layout); | |
465 | root_layout->addWidget(log_view_); | |
466 | ||
467 | QWidget *page = new QWidget(parent); | |
468 | page->setLayout(root_layout); | |
469 | ||
470 | return page; | |
471 | } | |
472 | ||
473 | void Settings::accept() | |
474 | { | |
475 | GlobalSettings settings; | |
476 | settings.stop_tracking(); | |
477 | ||
478 | QDialog::accept(); | |
479 | } | |
480 | ||
481 | void Settings::reject() | |
482 | { | |
483 | GlobalSettings settings; | |
484 | settings.undo_tracked_changes(); | |
485 | ||
486 | QDialog::reject(); | |
487 | } | |
488 | ||
489 | void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous) | |
490 | { | |
491 | if (!current) | |
492 | current = previous; | |
493 | ||
494 | pages->setCurrentIndex(page_list->row(current)); | |
495 | } | |
496 | ||
497 | void Settings::on_view_zoomToFitDuringAcq_changed(int state) | |
498 | { | |
499 | GlobalSettings settings; | |
500 | settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false); | |
501 | } | |
502 | ||
503 | void Settings::on_view_zoomToFitAfterAcq_changed(int state) | |
504 | { | |
505 | GlobalSettings settings; | |
506 | settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false); | |
507 | } | |
508 | ||
509 | void Settings::on_view_triggerIsZero_changed(int state) | |
510 | { | |
511 | GlobalSettings settings; | |
512 | settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false); | |
513 | } | |
514 | ||
515 | void Settings::on_view_coloredBG_changed(int state) | |
516 | { | |
517 | GlobalSettings settings; | |
518 | settings.setValue(GlobalSettings::Key_View_ColoredBG, state ? true : false); | |
519 | } | |
520 | ||
521 | void Settings::on_view_stickyScrolling_changed(int state) | |
522 | { | |
523 | GlobalSettings settings; | |
524 | settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false); | |
525 | } | |
526 | ||
527 | void Settings::on_view_showSamplingPoints_changed(int state) | |
528 | { | |
529 | GlobalSettings settings; | |
530 | settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false); | |
531 | } | |
532 | ||
533 | void Settings::on_view_showAnalogMinorGrid_changed(int state) | |
534 | { | |
535 | GlobalSettings settings; | |
536 | settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false); | |
537 | } | |
538 | ||
539 | void Settings::on_view_showHoverMarker_changed(int state) | |
540 | { | |
541 | GlobalSettings settings; | |
542 | settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, state ? true : false); | |
543 | } | |
544 | ||
545 | void Settings::on_view_snapDistance_changed(int value) | |
546 | { | |
547 | GlobalSettings settings; | |
548 | settings.setValue(GlobalSettings::Key_View_SnapDistance, value); | |
549 | } | |
550 | ||
551 | void Settings::on_view_conversionThresholdDispMode_changed(int state) | |
552 | { | |
553 | GlobalSettings settings; | |
554 | settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state); | |
555 | } | |
556 | ||
557 | void Settings::on_view_defaultDivHeight_changed(int value) | |
558 | { | |
559 | GlobalSettings settings; | |
560 | settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value); | |
561 | } | |
562 | ||
563 | void Settings::on_view_defaultLogicHeight_changed(int value) | |
564 | { | |
565 | GlobalSettings settings; | |
566 | settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value); | |
567 | } | |
568 | ||
569 | #ifdef ENABLE_DECODE | |
570 | void Settings::on_dec_initialStateConfigurable_changed(int state) | |
571 | { | |
572 | GlobalSettings settings; | |
573 | settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false); | |
574 | } | |
575 | ||
576 | void Settings::on_dec_exportFormat_changed(const QString &text) | |
577 | { | |
578 | GlobalSettings settings; | |
579 | settings.setValue(GlobalSettings::Key_Dec_ExportFormat, text); | |
580 | } | |
581 | #endif | |
582 | ||
583 | void Settings::on_log_logLevel_changed(int value) | |
584 | { | |
585 | logging.set_log_level(value); | |
586 | } | |
587 | ||
588 | void Settings::on_log_bufferSize_changed(int value) | |
589 | { | |
590 | GlobalSettings settings; | |
591 | settings.setValue(GlobalSettings::Key_Log_BufferSize, value); | |
592 | } | |
593 | ||
594 | void Settings::on_log_saveToFile_clicked(bool checked) | |
595 | { | |
596 | (void)checked; | |
597 | ||
598 | const QString file_name = QFileDialog::getSaveFileName( | |
599 | this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)")); | |
600 | ||
601 | if (file_name.isEmpty()) | |
602 | return; | |
603 | ||
604 | QFile file(file_name); | |
605 | if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { | |
606 | QTextStream out_stream(&file); | |
607 | out_stream << log_view_->toPlainText(); | |
608 | ||
609 | if (out_stream.status() == QTextStream::Ok) { | |
610 | QMessageBox msg(this); | |
611 | msg.setText(tr("Success")); | |
612 | msg.setInformativeText(tr("Log saved to %1.").arg(file_name)); | |
613 | msg.setStandardButtons(QMessageBox::Ok); | |
614 | msg.setIcon(QMessageBox::Information); | |
615 | msg.exec(); | |
616 | ||
617 | return; | |
618 | } | |
619 | } | |
620 | ||
621 | QMessageBox msg(this); | |
622 | msg.setText(tr("Error")); | |
623 | msg.setInformativeText(tr("File %1 could not be written to.").arg(file_name)); | |
624 | msg.setStandardButtons(QMessageBox::Ok); | |
625 | msg.setIcon(QMessageBox::Warning); | |
626 | msg.exec(); | |
627 | } | |
628 | ||
629 | void Settings::on_log_popOut_clicked(bool checked) | |
630 | { | |
631 | (void)checked; | |
632 | ||
633 | // Create the window as a sub-window so it closes when the main window closes | |
634 | QMainWindow *window = new QMainWindow(nullptr, Qt::SubWindow); | |
635 | ||
636 | window->setObjectName(QString::fromUtf8("Log Window")); | |
637 | window->setWindowTitle(tr("%1 Log").arg(PV_TITLE)); | |
638 | ||
639 | // Use same width/height as the settings dialog | |
640 | window->resize(width(), height()); | |
641 | ||
642 | window->setCentralWidget(create_log_view()); | |
643 | window->show(); | |
644 | } | |
645 | ||
646 | } // namespace dialogs | |
647 | } // namespace pv |