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