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