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