]>
Commit | Line | Data |
---|---|---|
bf9f1268 SA |
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 | ||
0f5e2c7d UH |
20 | #include "config.h" |
21 | ||
6579ca92 UH |
22 | #include <glib.h> |
23 | ||
4e4d72b2 | 24 | #include <QApplication> |
90ee1ed9 | 25 | #include <QComboBox> |
bf9f1268 | 26 | #include <QDialogButtonBox> |
bcb4c327 | 27 | #include <QFileDialog> |
bf9f1268 SA |
28 | #include <QFormLayout> |
29 | #include <QGroupBox> | |
b14db788 | 30 | #include <QHBoxLayout> |
4e4d72b2 | 31 | #include <QLabel> |
bcb4c327 SA |
32 | #include <QMainWindow> |
33 | #include <QMessageBox> | |
34 | #include <QPushButton> | |
03443f37 | 35 | #include <QScrollBar> |
daa54986 | 36 | #include <QSpinBox> |
4e4d72b2 SA |
37 | #include <QString> |
38 | #include <QTextBrowser> | |
39 | #include <QTextDocument> | |
bcb4c327 | 40 | #include <QTextStream> |
bf9f1268 SA |
41 | #include <QVBoxLayout> |
42 | ||
4e4d72b2 SA |
43 | #include "settings.hpp" |
44 | ||
49719858 | 45 | #include "pv/application.hpp" |
4e4d72b2 SA |
46 | #include "pv/devicemanager.hpp" |
47 | #include "pv/globalsettings.hpp" | |
bcb4c327 | 48 | #include "pv/logging.hpp" |
4521022b | 49 | #include "pv/widgets/colorbutton.hpp" |
4e4d72b2 SA |
50 | |
51 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
52 | ||
53 | #ifdef ENABLE_DECODE | |
54 | #include <libsigrokdecode/libsigrokdecode.h> | |
55 | #endif | |
56 | ||
6f925ba9 | 57 | using std::shared_ptr; |
4521022b | 58 | using pv::widgets::ColorButton; |
6f925ba9 | 59 | |
bf9f1268 SA |
60 | namespace pv { |
61 | namespace dialogs { | |
62 | ||
03443f37 SA |
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 | ||
4e4d72b2 SA |
86 | Settings::Settings(DeviceManager &device_manager, QWidget *parent) : |
87 | QDialog(parent, nullptr), | |
88 | device_manager_(device_manager) | |
bf9f1268 | 89 | { |
4e4d72b2 SA |
90 | resize(600, 400); |
91 | ||
bcb4c327 SA |
92 | // Create log view |
93 | log_view_ = create_log_view(); | |
94 | ||
95 | // Create pages | |
03443f37 SA |
96 | page_list = new PageListWidget(); |
97 | page_list->setViewMode(QListView::ListMode); | |
b14db788 | 98 | page_list->setMovement(QListView::Static); |
03443f37 | 99 | page_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
b14db788 SA |
100 | |
101 | pages = new QStackedWidget; | |
102 | create_pages(); | |
e6d42eec | 103 | page_list->setCurrentIndex(page_list->model()->index(0, 0)); |
b14db788 | 104 | |
03443f37 | 105 | // Create the rest of the dialog |
b14db788 SA |
106 | QHBoxLayout *tab_layout = new QHBoxLayout; |
107 | tab_layout->addWidget(page_list); | |
108 | tab_layout->addWidget(pages, Qt::AlignLeft); | |
bf9f1268 SA |
109 | |
110 | QDialogButtonBox *button_box = new QDialogButtonBox( | |
111 | QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | |
112 | ||
113 | QVBoxLayout* root_layout = new QVBoxLayout(this); | |
b14db788 | 114 | root_layout->addLayout(tab_layout); |
bf9f1268 SA |
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())); | |
b14db788 SA |
119 | connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), |
120 | this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*))); | |
2cca9ebf SA |
121 | |
122 | // Start to record changes | |
123 | GlobalSettings settings; | |
124 | settings.start_tracking(); | |
bf9f1268 SA |
125 | } |
126 | ||
b14db788 SA |
127 | void Settings::create_pages() |
128 | { | |
37b0bd35 SA |
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 | ||
b14db788 SA |
138 | // View page |
139 | pages->addWidget(get_view_settings_form(pages)); | |
140 | ||
141 | QListWidgetItem *viewButton = new QListWidgetItem(page_list); | |
2b0aa8fd | 142 | viewButton->setIcon(QIcon(":/icons/settings-views.svg")); |
b14db788 | 143 | viewButton->setText(tr("Views")); |
03443f37 | 144 | viewButton->setTextAlignment(Qt::AlignVCenter); |
b14db788 | 145 | viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
4e4d72b2 | 146 | |
669686c1 SA |
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")); | |
03443f37 | 154 | decoderButton->setTextAlignment(Qt::AlignVCenter); |
669686c1 SA |
155 | decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
156 | #endif | |
157 | ||
4e4d72b2 SA |
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")); | |
03443f37 | 164 | aboutButton->setTextAlignment(Qt::AlignVCenter); |
4e4d72b2 | 165 | aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
bcb4c327 SA |
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")); | |
03443f37 | 173 | loggingButton->setTextAlignment(Qt::AlignVCenter); |
bcb4c327 | 174 | loggingButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
b14db788 SA |
175 | } |
176 | ||
72df22b8 | 177 | QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const |
bf9f1268 SA |
178 | { |
179 | GlobalSettings settings; | |
180 | ||
72df22b8 SA |
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 | ||
bcb4c327 SA |
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 | ||
37b0bd35 SA |
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 (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 | return form; | |
233 | } | |
234 | ||
72df22b8 SA |
235 | QWidget *Settings::get_view_settings_form(QWidget *parent) const |
236 | { | |
daa54986 | 237 | GlobalSettings settings; |
72df22b8 SA |
238 | QCheckBox *cb; |
239 | ||
bf9f1268 SA |
240 | QWidget *form = new QWidget(parent); |
241 | QVBoxLayout *form_layout = new QVBoxLayout(form); | |
242 | ||
243 | // Trace view settings | |
244 | QGroupBox *trace_view_group = new QGroupBox(tr("Trace View")); | |
245 | form_layout->addWidget(trace_view_group); | |
246 | ||
247 | QFormLayout *trace_view_layout = new QFormLayout(); | |
248 | trace_view_group->setLayout(trace_view_layout); | |
249 | ||
641574bc SA |
250 | cb = create_checkbox(GlobalSettings::Key_View_ColoredBG, |
251 | SLOT(on_view_coloredBG_changed(int))); | |
252 | trace_view_layout->addRow(tr("Use colored trace &background"), cb); | |
bf9f1268 | 253 | |
e91fb166 SA |
254 | cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq, |
255 | SLOT(on_view_zoomToFitDuringAcq_changed(int))); | |
256 | trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb); | |
87a97d8a | 257 | |
28ceff25 SA |
258 | cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq, |
259 | SLOT(on_view_zoomToFitAfterAcq_changed(int))); | |
260 | trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb); | |
261 | ||
ffc00fdd C |
262 | cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime, |
263 | SLOT(on_view_triggerIsZero_changed(int))); | |
264 | trace_view_layout->addRow(tr("Show time zero at the trigger"), cb); | |
265 | ||
72df22b8 SA |
266 | cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling, |
267 | SLOT(on_view_stickyScrolling_changed(int))); | |
268 | trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb); | |
bf9f1268 | 269 | |
72df22b8 SA |
270 | cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints, |
271 | SLOT(on_view_showSamplingPoints_changed(int))); | |
272 | trace_view_layout->addRow(tr("Show data &sampling points"), cb); | |
051ba3b3 | 273 | |
4521022b SA |
274 | cb = create_checkbox(GlobalSettings::Key_View_FillSignalHighAreas, |
275 | SLOT(on_view_fillSignalHighAreas_changed(int))); | |
276 | trace_view_layout->addRow(tr("Fill high areas of logic signals"), cb); | |
277 | ||
278 | ColorButton* high_fill_cb = new ColorButton(parent); | |
279 | high_fill_cb->set_color(QColor::fromRgba( | |
280 | settings.value(GlobalSettings::Key_View_FillSignalHighAreaColor).value<uint32_t>())); | |
281 | connect(high_fill_cb, SIGNAL(selected(QColor)), | |
282 | this, SLOT(on_view_fillSignalHighAreaColor_changed(QColor))); | |
283 | trace_view_layout->addRow(tr("Fill high areas of logic signals"), high_fill_cb); | |
284 | ||
72df22b8 SA |
285 | cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid, |
286 | SLOT(on_view_showAnalogMinorGrid_changed(int))); | |
90ee1ed9 SA |
287 | trace_view_layout->addRow(tr("Show analog minor grid in addition to div grid"), cb); |
288 | ||
1931b5f9 SA |
289 | cb = create_checkbox(GlobalSettings::Key_View_ShowHoverMarker, |
290 | SLOT(on_view_showHoverMarker_changed(int))); | |
291 | trace_view_layout->addRow(tr("Highlight mouse cursor using a vertical marker line"), cb); | |
292 | ||
fb641801 SA |
293 | QSpinBox *snap_distance_sb = new QSpinBox(); |
294 | snap_distance_sb->setRange(0, 1000); | |
295 | snap_distance_sb->setSuffix(tr(" pixels")); | |
296 | snap_distance_sb->setValue( | |
297 | settings.value(GlobalSettings::Key_View_SnapDistance).toInt()); | |
298 | connect(snap_distance_sb, SIGNAL(valueChanged(int)), this, | |
299 | SLOT(on_view_snapDistance_changed(int))); | |
300 | trace_view_layout->addRow(tr("Maximum distance from edges before cursors snap to them"), snap_distance_sb); | |
301 | ||
90ee1ed9 SA |
302 | QComboBox *thr_disp_mode_cb = new QComboBox(); |
303 | thr_disp_mode_cb->addItem(tr("None"), GlobalSettings::ConvThrDispMode_None); | |
304 | thr_disp_mode_cb->addItem(tr("Background"), GlobalSettings::ConvThrDispMode_Background); | |
305 | thr_disp_mode_cb->addItem(tr("Dots"), GlobalSettings::ConvThrDispMode_Dots); | |
306 | thr_disp_mode_cb->setCurrentIndex( | |
307 | settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt()); | |
308 | connect(thr_disp_mode_cb, SIGNAL(currentIndexChanged(int)), | |
309 | this, SLOT(on_view_conversionThresholdDispMode_changed(int))); | |
310 | trace_view_layout->addRow(tr("Conversion threshold display mode (analog traces only)"), thr_disp_mode_cb); | |
4433246b | 311 | |
daa54986 SA |
312 | QSpinBox *default_div_height_sb = new QSpinBox(); |
313 | default_div_height_sb->setRange(20, 1000); | |
314 | default_div_height_sb->setSuffix(tr(" pixels")); | |
315 | default_div_height_sb->setValue( | |
316 | settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt()); | |
317 | connect(default_div_height_sb, SIGNAL(valueChanged(int)), this, | |
318 | SLOT(on_view_defaultDivHeight_changed(int))); | |
319 | trace_view_layout->addRow(tr("Default analog trace div height"), default_div_height_sb); | |
320 | ||
48051ccb SA |
321 | QSpinBox *default_logic_height_sb = new QSpinBox(); |
322 | default_logic_height_sb->setRange(5, 1000); | |
323 | default_logic_height_sb->setSuffix(tr(" pixels")); | |
324 | default_logic_height_sb->setValue( | |
325 | settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt()); | |
326 | connect(default_logic_height_sb, SIGNAL(valueChanged(int)), this, | |
327 | SLOT(on_view_defaultLogicHeight_changed(int))); | |
328 | trace_view_layout->addRow(tr("Default logic trace height"), default_logic_height_sb); | |
329 | ||
bf9f1268 SA |
330 | return form; |
331 | } | |
332 | ||
1ed996b4 | 333 | QWidget *Settings::get_decoder_settings_form(QWidget *parent) |
669686c1 SA |
334 | { |
335 | #ifdef ENABLE_DECODE | |
1ed996b4 | 336 | GlobalSettings settings; |
72df22b8 | 337 | QCheckBox *cb; |
669686c1 SA |
338 | |
339 | QWidget *form = new QWidget(parent); | |
340 | QVBoxLayout *form_layout = new QVBoxLayout(form); | |
341 | ||
342 | // Decoder settings | |
343 | QGroupBox *decoder_group = new QGroupBox(tr("Decoders")); | |
344 | form_layout->addWidget(decoder_group); | |
345 | ||
346 | QFormLayout *decoder_layout = new QFormLayout(); | |
347 | decoder_group->setLayout(decoder_layout); | |
348 | ||
72df22b8 SA |
349 | cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable, |
350 | SLOT(on_dec_initialStateConfigurable_changed(int))); | |
351 | decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb); | |
1cc1c8de | 352 | |
1ed996b4 SA |
353 | // Annotation export settings |
354 | ann_export_format_ = new QLineEdit(); | |
355 | ann_export_format_->setText( | |
356 | settings.value(GlobalSettings::Key_Dec_ExportFormat).toString()); | |
357 | connect(ann_export_format_, SIGNAL(textChanged(const QString&)), | |
358 | this, SLOT(on_dec_exportFormat_changed(const QString&))); | |
359 | decoder_layout->addRow(tr("Annotation export format"), ann_export_format_); | |
39e047cf | 360 | QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %c: row name; %q: use quotations marks")); |
1ed996b4 SA |
361 | description_1->setAlignment(Qt::AlignRight); |
362 | decoder_layout->addRow(description_1); | |
363 | QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts")); | |
364 | description_2->setAlignment(Qt::AlignRight); | |
365 | decoder_layout->addRow(description_2); | |
366 | ||
669686c1 SA |
367 | return form; |
368 | #else | |
369 | (void)parent; | |
7773ccae | 370 | return nullptr; |
669686c1 SA |
371 | #endif |
372 | } | |
373 | ||
4e4d72b2 SA |
374 | QWidget *Settings::get_about_page(QWidget *parent) const |
375 | { | |
49719858 | 376 | Application* a = qobject_cast<Application*>(QApplication::instance()); |
4e4d72b2 SA |
377 | |
378 | QLabel *icon = new QLabel(); | |
311da121 | 379 | icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg"))); |
4e4d72b2 | 380 | |
49719858 | 381 | // Setup the license field with the project homepage link |
b804a6da GS |
382 | QLabel *gpl_home_info = new QLabel(); |
383 | gpl_home_info->setText(tr("%1<br /><a href=\"http://%2\">%2</a>").arg( | |
4e4d72b2 SA |
384 | tr("GNU GPL, version 3 or later"), |
385 | QApplication::organizationDomain())); | |
b804a6da | 386 | gpl_home_info->setOpenExternalLinks(true); |
4e4d72b2 | 387 | |
4e4d72b2 | 388 | QString s; |
d008cab1 ML |
389 | |
390 | s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>"); | |
391 | ||
4e4d72b2 SA |
392 | s.append("<table>"); |
393 | ||
b804a6da | 394 | s.append("<tr><td colspan=\"2\"><b>" + |
d3d55ad3 | 395 | tr("Versions, libraries and features:") + "</b></td></tr>"); |
49719858 SA |
396 | for (pair<QString, QString> &entry : a->get_version_info()) |
397 | s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>") | |
398 | .arg(entry.first, entry.second)); | |
20c80c8a | 399 | |
bf84211b SA |
400 | s.append("<tr><td colspan=\"2\"></td></tr>"); |
401 | s.append("<tr><td colspan=\"2\"><b>" + | |
402 | tr("Firmware search paths:") + "</b></td></tr>"); | |
49719858 SA |
403 | for (QString &entry : a->get_fw_path_list()) |
404 | s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry)); | |
bf84211b SA |
405 | |
406 | #ifdef ENABLE_DECODE | |
407 | s.append("<tr><td colspan=\"2\"></td></tr>"); | |
408 | s.append("<tr><td colspan=\"2\"><b>" + | |
409 | tr("Protocol decoder search paths:") + "</b></td></tr>"); | |
49719858 SA |
410 | for (QString &entry : a->get_pd_path_list()) |
411 | s.append(QString("<tr><td colspan=\"2\">%1</td></tr>").arg(entry)); | |
bf84211b SA |
412 | #endif |
413 | ||
edfe64fd | 414 | s.append("<tr><td colspan=\"2\"></td></tr>"); |
4e4d72b2 | 415 | s.append("<tr><td colspan=\"2\"><b>" + |
c063290a | 416 | tr("Supported hardware drivers:") + "</b></td></tr>"); |
49719858 | 417 | for (pair<QString, QString> &entry : a->get_driver_list()) |
d008cab1 | 418 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") |
49719858 | 419 | .arg(entry.first, entry.second)); |
4e4d72b2 | 420 | |
edfe64fd | 421 | s.append("<tr><td colspan=\"2\"></td></tr>"); |
4e4d72b2 | 422 | s.append("<tr><td colspan=\"2\"><b>" + |
c063290a | 423 | tr("Supported input formats:") + "</b></td></tr>"); |
49719858 | 424 | for (pair<QString, QString> &entry : a->get_input_format_list()) |
d008cab1 | 425 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") |
49719858 | 426 | .arg(entry.first, entry.second)); |
4e4d72b2 | 427 | |
edfe64fd | 428 | s.append("<tr><td colspan=\"2\"></td></tr>"); |
4e4d72b2 | 429 | s.append("<tr><td colspan=\"2\"><b>" + |
c063290a | 430 | tr("Supported output formats:") + "</b></td></tr>"); |
49719858 | 431 | for (pair<QString, QString> &entry : a->get_output_format_list()) |
d008cab1 | 432 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") |
49719858 | 433 | .arg(entry.first, entry.second)); |
4e4d72b2 SA |
434 | |
435 | #ifdef ENABLE_DECODE | |
edfe64fd | 436 | s.append("<tr><td colspan=\"2\"></td></tr>"); |
4e4d72b2 | 437 | s.append("<tr><td colspan=\"2\"><b>" + |
c063290a | 438 | tr("Supported protocol decoders:") + "</b></td></tr>"); |
49719858 | 439 | for (pair<QString, QString> &entry : a->get_pd_list()) |
d008cab1 | 440 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") |
49719858 | 441 | .arg(entry.first, entry.second)); |
4e4d72b2 SA |
442 | #endif |
443 | ||
444 | s.append("</table>"); | |
445 | ||
446 | QTextDocument *supported_doc = new QTextDocument(); | |
447 | supported_doc->setHtml(s); | |
448 | ||
449 | QTextBrowser *support_list = new QTextBrowser(); | |
450 | support_list->setDocument(supported_doc); | |
451 | ||
7d9dd6f4 UH |
452 | QHBoxLayout *h_layout = new QHBoxLayout(); |
453 | h_layout->setAlignment(Qt::AlignLeft); | |
454 | h_layout->addWidget(icon); | |
455 | h_layout->addWidget(gpl_home_info); | |
456 | ||
457 | QVBoxLayout *layout = new QVBoxLayout(); | |
458 | layout->addLayout(h_layout); | |
459 | layout->addWidget(support_list); | |
4e4d72b2 SA |
460 | |
461 | QWidget *page = new QWidget(parent); | |
462 | page->setLayout(layout); | |
463 | ||
464 | return page; | |
465 | } | |
466 | ||
bcb4c327 SA |
467 | QWidget *Settings::get_logging_page(QWidget *parent) const |
468 | { | |
469 | GlobalSettings settings; | |
470 | ||
471 | // Log level | |
472 | QSpinBox *loglevel_sb = new QSpinBox(); | |
473 | loglevel_sb->setMaximum(SR_LOG_SPEW); | |
474 | loglevel_sb->setValue(logging.get_log_level()); | |
475 | connect(loglevel_sb, SIGNAL(valueChanged(int)), this, | |
476 | SLOT(on_log_logLevel_changed(int))); | |
477 | ||
478 | QHBoxLayout *loglevel_layout = new QHBoxLayout(); | |
479 | loglevel_layout->addWidget(new QLabel(tr("Log level:"))); | |
480 | loglevel_layout->addWidget(loglevel_sb); | |
481 | ||
482 | // Background buffer size | |
483 | QSpinBox *buffersize_sb = new QSpinBox(); | |
484 | buffersize_sb->setSuffix(tr(" lines")); | |
b9a3a67e | 485 | buffersize_sb->setMinimum(Logging::MIN_BUFFER_SIZE); |
bcb4c327 SA |
486 | buffersize_sb->setMaximum(Logging::MAX_BUFFER_SIZE); |
487 | buffersize_sb->setValue( | |
488 | settings.value(GlobalSettings::Key_Log_BufferSize).toInt()); | |
489 | connect(buffersize_sb, SIGNAL(valueChanged(int)), this, | |
490 | SLOT(on_log_bufferSize_changed(int))); | |
491 | ||
492 | QHBoxLayout *buffersize_layout = new QHBoxLayout(); | |
493 | buffersize_layout->addWidget(new QLabel(tr("Length of background buffer:"))); | |
494 | buffersize_layout->addWidget(buffersize_sb); | |
495 | ||
496 | // Save to file | |
497 | QPushButton *save_log_pb = new QPushButton( | |
498 | QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png")), | |
499 | tr("&Save to File")); | |
500 | connect(save_log_pb, SIGNAL(clicked(bool)), | |
501 | this, SLOT(on_log_saveToFile_clicked(bool))); | |
502 | ||
503 | // Pop out | |
504 | QPushButton *pop_out_pb = new QPushButton( | |
505 | QIcon::fromTheme("window-new", QIcon(":/icons/window-new.png")), | |
506 | tr("&Pop out")); | |
507 | connect(pop_out_pb, SIGNAL(clicked(bool)), | |
508 | this, SLOT(on_log_popOut_clicked(bool))); | |
509 | ||
510 | QHBoxLayout *control_layout = new QHBoxLayout(); | |
511 | control_layout->addLayout(loglevel_layout); | |
512 | control_layout->addLayout(buffersize_layout); | |
513 | control_layout->addWidget(save_log_pb); | |
514 | control_layout->addWidget(pop_out_pb); | |
515 | ||
516 | QVBoxLayout *root_layout = new QVBoxLayout(); | |
517 | root_layout->addLayout(control_layout); | |
518 | root_layout->addWidget(log_view_); | |
519 | ||
520 | QWidget *page = new QWidget(parent); | |
521 | page->setLayout(root_layout); | |
522 | ||
523 | return page; | |
524 | } | |
525 | ||
bf9f1268 SA |
526 | void Settings::accept() |
527 | { | |
2cca9ebf SA |
528 | GlobalSettings settings; |
529 | settings.stop_tracking(); | |
530 | ||
bf9f1268 SA |
531 | QDialog::accept(); |
532 | } | |
533 | ||
534 | void Settings::reject() | |
535 | { | |
2cca9ebf SA |
536 | GlobalSettings settings; |
537 | settings.undo_tracked_changes(); | |
538 | ||
bf9f1268 SA |
539 | QDialog::reject(); |
540 | } | |
541 | ||
b14db788 SA |
542 | void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous) |
543 | { | |
544 | if (!current) | |
545 | current = previous; | |
546 | ||
547 | pages->setCurrentIndex(page_list->row(current)); | |
548 | } | |
549 | ||
37b0bd35 SA |
550 | void Settings::on_general_theme_changed_changed(int state) |
551 | { | |
552 | GlobalSettings settings; | |
553 | settings.setValue(GlobalSettings::Key_General_Theme, state); | |
554 | settings.apply_theme(); | |
555 | } | |
556 | ||
e91fb166 | 557 | void Settings::on_view_zoomToFitDuringAcq_changed(int state) |
bf9f1268 SA |
558 | { |
559 | GlobalSettings settings; | |
e91fb166 | 560 | settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false); |
bf9f1268 SA |
561 | } |
562 | ||
28ceff25 SA |
563 | void Settings::on_view_zoomToFitAfterAcq_changed(int state) |
564 | { | |
565 | GlobalSettings settings; | |
566 | settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false); | |
567 | } | |
568 | ||
ffc00fdd C |
569 | void Settings::on_view_triggerIsZero_changed(int state) |
570 | { | |
571 | GlobalSettings settings; | |
572 | settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false); | |
573 | } | |
574 | ||
641574bc | 575 | void Settings::on_view_coloredBG_changed(int state) |
bf9f1268 SA |
576 | { |
577 | GlobalSettings settings; | |
641574bc | 578 | settings.setValue(GlobalSettings::Key_View_ColoredBG, state ? true : false); |
bf9f1268 SA |
579 | } |
580 | ||
87a97d8a SA |
581 | void Settings::on_view_stickyScrolling_changed(int state) |
582 | { | |
583 | GlobalSettings settings; | |
584 | settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false); | |
585 | } | |
586 | ||
051ba3b3 UH |
587 | void Settings::on_view_showSamplingPoints_changed(int state) |
588 | { | |
589 | GlobalSettings settings; | |
590 | settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false); | |
591 | } | |
87a97d8a | 592 | |
4521022b SA |
593 | void Settings::on_view_fillSignalHighAreas_changed(int state) |
594 | { | |
595 | GlobalSettings settings; | |
596 | settings.setValue(GlobalSettings::Key_View_FillSignalHighAreas, state ? true : false); | |
597 | } | |
598 | ||
599 | void Settings::on_view_fillSignalHighAreaColor_changed(QColor color) | |
600 | { | |
601 | GlobalSettings settings; | |
602 | settings.setValue(GlobalSettings::Key_View_FillSignalHighAreaColor, color.rgba()); | |
603 | } | |
604 | ||
8ad61f40 UH |
605 | void Settings::on_view_showAnalogMinorGrid_changed(int state) |
606 | { | |
607 | GlobalSettings settings; | |
608 | settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false); | |
609 | } | |
610 | ||
1931b5f9 SA |
611 | void Settings::on_view_showHoverMarker_changed(int state) |
612 | { | |
613 | GlobalSettings settings; | |
614 | settings.setValue(GlobalSettings::Key_View_ShowHoverMarker, state ? true : false); | |
615 | } | |
616 | ||
fb641801 SA |
617 | void Settings::on_view_snapDistance_changed(int value) |
618 | { | |
619 | GlobalSettings settings; | |
620 | settings.setValue(GlobalSettings::Key_View_SnapDistance, value); | |
621 | } | |
622 | ||
90ee1ed9 | 623 | void Settings::on_view_conversionThresholdDispMode_changed(int state) |
4433246b SA |
624 | { |
625 | GlobalSettings settings; | |
90ee1ed9 | 626 | settings.setValue(GlobalSettings::Key_View_ConversionThresholdDispMode, state); |
4433246b SA |
627 | } |
628 | ||
daa54986 SA |
629 | void Settings::on_view_defaultDivHeight_changed(int value) |
630 | { | |
631 | GlobalSettings settings; | |
632 | settings.setValue(GlobalSettings::Key_View_DefaultDivHeight, value); | |
633 | } | |
634 | ||
48051ccb SA |
635 | void Settings::on_view_defaultLogicHeight_changed(int value) |
636 | { | |
637 | GlobalSettings settings; | |
638 | settings.setValue(GlobalSettings::Key_View_DefaultLogicHeight, value); | |
639 | } | |
640 | ||
1ed996b4 | 641 | #ifdef ENABLE_DECODE |
1cc1c8de SA |
642 | void Settings::on_dec_initialStateConfigurable_changed(int state) |
643 | { | |
644 | GlobalSettings settings; | |
645 | settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false); | |
646 | } | |
647 | ||
1ed996b4 SA |
648 | void Settings::on_dec_exportFormat_changed(const QString &text) |
649 | { | |
650 | GlobalSettings settings; | |
651 | settings.setValue(GlobalSettings::Key_Dec_ExportFormat, text); | |
652 | } | |
653 | #endif | |
654 | ||
bcb4c327 SA |
655 | void Settings::on_log_logLevel_changed(int value) |
656 | { | |
657 | logging.set_log_level(value); | |
658 | } | |
659 | ||
660 | void Settings::on_log_bufferSize_changed(int value) | |
661 | { | |
662 | GlobalSettings settings; | |
663 | settings.setValue(GlobalSettings::Key_Log_BufferSize, value); | |
664 | } | |
665 | ||
666 | void Settings::on_log_saveToFile_clicked(bool checked) | |
667 | { | |
668 | (void)checked; | |
669 | ||
670 | const QString file_name = QFileDialog::getSaveFileName( | |
671 | this, tr("Save Log"), "", tr("Log Files (*.txt *.log);;All Files (*)")); | |
672 | ||
673 | if (file_name.isEmpty()) | |
674 | return; | |
675 | ||
676 | QFile file(file_name); | |
677 | if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { | |
678 | QTextStream out_stream(&file); | |
679 | out_stream << log_view_->toPlainText(); | |
680 | ||
681 | if (out_stream.status() == QTextStream::Ok) { | |
682 | QMessageBox msg(this); | |
683 | msg.setText(tr("Success")); | |
684 | msg.setInformativeText(tr("Log saved to %1.").arg(file_name)); | |
685 | msg.setStandardButtons(QMessageBox::Ok); | |
686 | msg.setIcon(QMessageBox::Information); | |
687 | msg.exec(); | |
688 | ||
689 | return; | |
690 | } | |
691 | } | |
692 | ||
693 | QMessageBox msg(this); | |
694 | msg.setText(tr("Error")); | |
695 | msg.setInformativeText(tr("File %1 could not be written to.").arg(file_name)); | |
696 | msg.setStandardButtons(QMessageBox::Ok); | |
697 | msg.setIcon(QMessageBox::Warning); | |
698 | msg.exec(); | |
699 | } | |
700 | ||
701 | void Settings::on_log_popOut_clicked(bool checked) | |
702 | { | |
703 | (void)checked; | |
704 | ||
705 | // Create the window as a sub-window so it closes when the main window closes | |
37134086 | 706 | QMainWindow *window = new QMainWindow(nullptr, Qt::SubWindow); |
bcb4c327 SA |
707 | |
708 | window->setObjectName(QString::fromUtf8("Log Window")); | |
709 | window->setWindowTitle(tr("%1 Log").arg(PV_TITLE)); | |
710 | ||
711 | // Use same width/height as the settings dialog | |
712 | window->resize(width(), height()); | |
713 | ||
714 | window->setCentralWidget(create_log_view()); | |
715 | window->show(); | |
716 | } | |
717 | ||
bf9f1268 SA |
718 | } // namespace dialogs |
719 | } // namespace pv |