]>
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 | 22 | #include <glib.h> |
0f5e2c7d | 23 | #include <boost/version.hpp> |
6579ca92 | 24 | |
4e4d72b2 | 25 | #include <QApplication> |
bf9f1268 SA |
26 | #include <QDialogButtonBox> |
27 | #include <QFormLayout> | |
28 | #include <QGroupBox> | |
b14db788 | 29 | #include <QHBoxLayout> |
4e4d72b2 SA |
30 | #include <QLabel> |
31 | #include <QString> | |
32 | #include <QTextBrowser> | |
33 | #include <QTextDocument> | |
bf9f1268 SA |
34 | #include <QVBoxLayout> |
35 | ||
4e4d72b2 SA |
36 | #include "settings.hpp" |
37 | ||
38 | #include "pv/devicemanager.hpp" | |
39 | #include "pv/globalsettings.hpp" | |
40 | ||
41 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
42 | ||
43 | #ifdef ENABLE_DECODE | |
44 | #include <libsigrokdecode/libsigrokdecode.h> | |
45 | #endif | |
46 | ||
6f925ba9 UH |
47 | using std::shared_ptr; |
48 | ||
bf9f1268 SA |
49 | namespace pv { |
50 | namespace dialogs { | |
51 | ||
4e4d72b2 SA |
52 | Settings::Settings(DeviceManager &device_manager, QWidget *parent) : |
53 | QDialog(parent, nullptr), | |
54 | device_manager_(device_manager) | |
bf9f1268 | 55 | { |
b14db788 SA |
56 | const int icon_size = 64; |
57 | ||
4e4d72b2 SA |
58 | resize(600, 400); |
59 | ||
b14db788 SA |
60 | page_list = new QListWidget; |
61 | page_list->setViewMode(QListView::IconMode); | |
62 | page_list->setIconSize(QSize(icon_size, icon_size)); | |
63 | page_list->setMovement(QListView::Static); | |
c063290a | 64 | page_list->setMaximumWidth(icon_size + (icon_size / 2)); |
b14db788 SA |
65 | page_list->setSpacing(12); |
66 | ||
67 | pages = new QStackedWidget; | |
68 | create_pages(); | |
e6d42eec | 69 | page_list->setCurrentIndex(page_list->model()->index(0, 0)); |
b14db788 SA |
70 | |
71 | QHBoxLayout *tab_layout = new QHBoxLayout; | |
72 | tab_layout->addWidget(page_list); | |
73 | tab_layout->addWidget(pages, Qt::AlignLeft); | |
bf9f1268 SA |
74 | |
75 | QDialogButtonBox *button_box = new QDialogButtonBox( | |
76 | QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | |
77 | ||
78 | QVBoxLayout* root_layout = new QVBoxLayout(this); | |
b14db788 | 79 | root_layout->addLayout(tab_layout); |
bf9f1268 SA |
80 | root_layout->addWidget(button_box); |
81 | ||
82 | connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); | |
83 | connect(button_box, SIGNAL(rejected()), this, SLOT(reject())); | |
b14db788 SA |
84 | connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), |
85 | this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*))); | |
2cca9ebf SA |
86 | |
87 | // Start to record changes | |
88 | GlobalSettings settings; | |
89 | settings.start_tracking(); | |
bf9f1268 SA |
90 | } |
91 | ||
b14db788 SA |
92 | void Settings::create_pages() |
93 | { | |
94 | // View page | |
95 | pages->addWidget(get_view_settings_form(pages)); | |
96 | ||
97 | QListWidgetItem *viewButton = new QListWidgetItem(page_list); | |
2b0aa8fd | 98 | viewButton->setIcon(QIcon(":/icons/settings-views.svg")); |
b14db788 SA |
99 | viewButton->setText(tr("Views")); |
100 | viewButton->setTextAlignment(Qt::AlignHCenter); | |
101 | viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
4e4d72b2 | 102 | |
669686c1 SA |
103 | #ifdef ENABLE_DECODE |
104 | // Decoder page | |
105 | pages->addWidget(get_decoder_settings_form(pages)); | |
106 | ||
107 | QListWidgetItem *decoderButton = new QListWidgetItem(page_list); | |
108 | decoderButton->setIcon(QIcon(":/icons/add-decoder.svg")); | |
109 | decoderButton->setText(tr("Decoders")); | |
110 | decoderButton->setTextAlignment(Qt::AlignHCenter); | |
111 | decoderButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
112 | #endif | |
113 | ||
4e4d72b2 SA |
114 | // About page |
115 | pages->addWidget(get_about_page(pages)); | |
116 | ||
117 | QListWidgetItem *aboutButton = new QListWidgetItem(page_list); | |
118 | aboutButton->setIcon(QIcon(":/icons/information.svg")); | |
119 | aboutButton->setText(tr("About")); | |
120 | aboutButton->setTextAlignment(Qt::AlignHCenter); | |
121 | aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); | |
b14db788 SA |
122 | } |
123 | ||
72df22b8 | 124 | QCheckBox *Settings::create_checkbox(const QString& key, const char* slot) const |
bf9f1268 SA |
125 | { |
126 | GlobalSettings settings; | |
127 | ||
72df22b8 SA |
128 | QCheckBox *cb = new QCheckBox(); |
129 | cb->setChecked(settings.value(key).toBool()); | |
130 | connect(cb, SIGNAL(stateChanged(int)), this, slot); | |
131 | return cb; | |
132 | } | |
133 | ||
134 | QWidget *Settings::get_view_settings_form(QWidget *parent) const | |
135 | { | |
136 | QCheckBox *cb; | |
137 | ||
bf9f1268 SA |
138 | QWidget *form = new QWidget(parent); |
139 | QVBoxLayout *form_layout = new QVBoxLayout(form); | |
140 | ||
141 | // Trace view settings | |
142 | QGroupBox *trace_view_group = new QGroupBox(tr("Trace View")); | |
143 | form_layout->addWidget(trace_view_group); | |
144 | ||
145 | QFormLayout *trace_view_layout = new QFormLayout(); | |
146 | trace_view_group->setLayout(trace_view_layout); | |
147 | ||
72df22b8 SA |
148 | cb = create_checkbox(GlobalSettings::Key_View_ColouredBG, |
149 | SLOT(on_view_colouredBG_changed(int))); | |
150 | trace_view_layout->addRow(tr("Use coloured trace &background"), cb); | |
bf9f1268 | 151 | |
e91fb166 SA |
152 | cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitDuringAcq, |
153 | SLOT(on_view_zoomToFitDuringAcq_changed(int))); | |
154 | trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during acquisition"), cb); | |
87a97d8a | 155 | |
28ceff25 SA |
156 | cb = create_checkbox(GlobalSettings::Key_View_ZoomToFitAfterAcq, |
157 | SLOT(on_view_zoomToFitAfterAcq_changed(int))); | |
158 | trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb); | |
159 | ||
72df22b8 SA |
160 | cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling, |
161 | SLOT(on_view_stickyScrolling_changed(int))); | |
162 | trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb); | |
bf9f1268 | 163 | |
72df22b8 SA |
164 | cb = create_checkbox(GlobalSettings::Key_View_ShowSamplingPoints, |
165 | SLOT(on_view_showSamplingPoints_changed(int))); | |
166 | trace_view_layout->addRow(tr("Show data &sampling points"), cb); | |
051ba3b3 | 167 | |
72df22b8 SA |
168 | cb = create_checkbox(GlobalSettings::Key_View_ShowAnalogMinorGrid, |
169 | SLOT(on_view_showAnalogMinorGrid_changed(int))); | |
170 | trace_view_layout->addRow(tr("Show analog minor grid in addition to vdiv grid"), cb); | |
8ad61f40 | 171 | |
bf9f1268 SA |
172 | return form; |
173 | } | |
174 | ||
669686c1 SA |
175 | QWidget *Settings::get_decoder_settings_form(QWidget *parent) const |
176 | { | |
177 | #ifdef ENABLE_DECODE | |
72df22b8 | 178 | QCheckBox *cb; |
669686c1 SA |
179 | |
180 | QWidget *form = new QWidget(parent); | |
181 | QVBoxLayout *form_layout = new QVBoxLayout(form); | |
182 | ||
183 | // Decoder settings | |
184 | QGroupBox *decoder_group = new QGroupBox(tr("Decoders")); | |
185 | form_layout->addWidget(decoder_group); | |
186 | ||
187 | QFormLayout *decoder_layout = new QFormLayout(); | |
188 | decoder_group->setLayout(decoder_layout); | |
189 | ||
72df22b8 SA |
190 | cb = create_checkbox(GlobalSettings::Key_Dec_InitialStateConfigurable, |
191 | SLOT(on_dec_initialStateConfigurable_changed(int))); | |
192 | decoder_layout->addRow(tr("Allow configuration of &initial signal state"), cb); | |
1cc1c8de | 193 | |
669686c1 SA |
194 | return form; |
195 | #else | |
196 | (void)parent; | |
197 | #endif | |
198 | } | |
199 | ||
fe934a93 GS |
200 | #ifdef ENABLE_DECODE |
201 | static gint sort_pds(gconstpointer a, gconstpointer b) | |
202 | { | |
203 | const struct srd_decoder *sda, *sdb; | |
204 | ||
205 | sda = (const struct srd_decoder *)a; | |
206 | sdb = (const struct srd_decoder *)b; | |
207 | return strcmp(sda->id, sdb->id); | |
208 | } | |
209 | #endif | |
210 | ||
4e4d72b2 SA |
211 | QWidget *Settings::get_about_page(QWidget *parent) const |
212 | { | |
213 | #ifdef ENABLE_DECODE | |
214 | struct srd_decoder *dec; | |
215 | #endif | |
216 | ||
217 | QLabel *icon = new QLabel(); | |
311da121 | 218 | icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/pulseview.svg"))); |
4e4d72b2 SA |
219 | |
220 | /* Setup the version field */ | |
221 | QLabel *version_info = new QLabel(); | |
222 | version_info->setText(tr("%1 %2<br />%3<br /><a href=\"http://%4\">%4</a>") | |
223 | .arg(QApplication::applicationName(), | |
224 | QApplication::applicationVersion(), | |
225 | tr("GNU GPL, version 3 or later"), | |
226 | QApplication::organizationDomain())); | |
227 | version_info->setOpenExternalLinks(true); | |
228 | ||
6f925ba9 | 229 | shared_ptr<sigrok::Context> context = device_manager_.context(); |
4e4d72b2 SA |
230 | |
231 | QString s; | |
d008cab1 ML |
232 | |
233 | s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>"); | |
234 | ||
4e4d72b2 SA |
235 | s.append("<table>"); |
236 | ||
20c80c8a SA |
237 | /* Library info */ |
238 | s.append("<tr><td colspan=\"2\"><b>" + | |
6579ca92 | 239 | tr("Libraries and features:") + "</b></td></tr>"); |
0f5e2c7d | 240 | |
20c80c8a | 241 | s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>") |
213db299 | 242 | .arg(QString("Qt"), qVersion())); |
0f5e2c7d UH |
243 | s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>") |
244 | .arg(QString("glibmm"), PV_GLIBMM_VERSION)); | |
245 | s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>") | |
246 | .arg(QString("Boost"), BOOST_LIB_VERSION)); | |
247 | ||
248 | s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>") | |
249 | .arg(QString("libsigrok"), SR_PACKAGE_VERSION_STRING, | |
250 | SR_LIB_VERSION_STRING, sr_package_version_string_get(), | |
251 | sr_lib_version_string_get())); | |
6579ca92 UH |
252 | |
253 | GSList *l_orig = sr_buildinfo_libs_get(); | |
254 | for (GSList *l = l_orig; l; l = l->next) { | |
255 | GSList *m = (GSList *)l->data; | |
256 | const char *lib = (const char *)m->data; | |
257 | const char *version = (const char *)m->next->data; | |
258 | s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>") | |
259 | .arg(QString(lib), QString(version))); | |
260 | g_slist_free_full(m, g_free); | |
261 | } | |
262 | g_slist_free(l_orig); | |
263 | ||
264 | char *host = sr_buildinfo_host_get(); | |
265 | s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>") | |
266 | .arg(QString(host))); | |
267 | g_free(host); | |
268 | ||
269 | char *scpi_backends = sr_buildinfo_scpi_backends_get(); | |
270 | s.append(QString("<tr><td><i>- SCPI backends</i></td><td>%1</td></tr>") | |
271 | .arg(QString(scpi_backends))); | |
272 | g_free(scpi_backends); | |
273 | ||
6c348830 | 274 | #ifdef ENABLE_DECODE |
0f5e2c7d UH |
275 | s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>") |
276 | .arg(QString("libsigrokdecode"), SRD_PACKAGE_VERSION_STRING, | |
277 | SRD_LIB_VERSION_STRING, srd_package_version_string_get(), | |
278 | srd_lib_version_string_get())); | |
279 | ||
280 | l_orig = srd_buildinfo_libs_get(); | |
281 | for (GSList *l = l_orig; l; l = l->next) { | |
282 | GSList *m = (GSList *)l->data; | |
283 | const char *lib = (const char *)m->data; | |
284 | const char *version = (const char *)m->next->data; | |
285 | s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>") | |
286 | .arg(QString(lib), QString(version))); | |
287 | g_slist_free_full(m, g_free); | |
288 | } | |
289 | g_slist_free(l_orig); | |
290 | ||
291 | host = srd_buildinfo_host_get(); | |
292 | s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>") | |
293 | .arg(QString(host))); | |
294 | g_free(host); | |
6c348830 | 295 | #endif |
20c80c8a | 296 | |
4e4d72b2 | 297 | /* Set up the supported field */ |
edfe64fd | 298 | s.append("<tr><td colspan=\"2\"></td></tr>"); |
4e4d72b2 | 299 | s.append("<tr><td colspan=\"2\"><b>" + |
c063290a | 300 | tr("Supported hardware drivers:") + "</b></td></tr>"); |
4e4d72b2 | 301 | for (auto entry : context->drivers()) { |
d008cab1 | 302 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") |
4e4d72b2 SA |
303 | .arg(QString::fromUtf8(entry.first.c_str()), |
304 | QString::fromUtf8(entry.second->long_name().c_str()))); | |
305 | } | |
306 | ||
edfe64fd | 307 | s.append("<tr><td colspan=\"2\"></td></tr>"); |
4e4d72b2 | 308 | s.append("<tr><td colspan=\"2\"><b>" + |
c063290a | 309 | tr("Supported input formats:") + "</b></td></tr>"); |
4e4d72b2 | 310 | for (auto entry : context->input_formats()) { |
d008cab1 | 311 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") |
4e4d72b2 SA |
312 | .arg(QString::fromUtf8(entry.first.c_str()), |
313 | QString::fromUtf8(entry.second->description().c_str()))); | |
314 | } | |
315 | ||
edfe64fd | 316 | s.append("<tr><td colspan=\"2\"></td></tr>"); |
4e4d72b2 | 317 | s.append("<tr><td colspan=\"2\"><b>" + |
c063290a | 318 | tr("Supported output formats:") + "</b></td></tr>"); |
4e4d72b2 | 319 | for (auto entry : context->output_formats()) { |
d008cab1 | 320 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") |
4e4d72b2 SA |
321 | .arg(QString::fromUtf8(entry.first.c_str()), |
322 | QString::fromUtf8(entry.second->description().c_str()))); | |
323 | } | |
324 | ||
325 | #ifdef ENABLE_DECODE | |
edfe64fd | 326 | s.append("<tr><td colspan=\"2\"></td></tr>"); |
4e4d72b2 | 327 | s.append("<tr><td colspan=\"2\"><b>" + |
c063290a | 328 | tr("Supported protocol decoders:") + "</b></td></tr>"); |
fe934a93 GS |
329 | GSList *sl = g_slist_copy((GSList *)srd_decoder_list()); |
330 | sl = g_slist_sort(sl, sort_pds); | |
331 | for (const GSList *l = sl; l; l = l->next) { | |
4e4d72b2 | 332 | dec = (struct srd_decoder *)l->data; |
d008cab1 | 333 | s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>") |
4e4d72b2 SA |
334 | .arg(QString::fromUtf8(dec->id), |
335 | QString::fromUtf8(dec->longname))); | |
336 | } | |
fe934a93 | 337 | g_slist_free(sl); |
4e4d72b2 SA |
338 | #endif |
339 | ||
340 | s.append("</table>"); | |
341 | ||
342 | QTextDocument *supported_doc = new QTextDocument(); | |
343 | supported_doc->setHtml(s); | |
344 | ||
345 | QTextBrowser *support_list = new QTextBrowser(); | |
346 | support_list->setDocument(supported_doc); | |
347 | ||
348 | QGridLayout *layout = new QGridLayout(); | |
349 | layout->addWidget(icon, 0, 0, 1, 1); | |
350 | layout->addWidget(version_info, 0, 1, 1, 1); | |
351 | layout->addWidget(support_list, 1, 1, 1, 1); | |
352 | ||
353 | QWidget *page = new QWidget(parent); | |
354 | page->setLayout(layout); | |
355 | ||
356 | return page; | |
357 | } | |
358 | ||
bf9f1268 SA |
359 | void Settings::accept() |
360 | { | |
2cca9ebf SA |
361 | GlobalSettings settings; |
362 | settings.stop_tracking(); | |
363 | ||
bf9f1268 SA |
364 | QDialog::accept(); |
365 | } | |
366 | ||
367 | void Settings::reject() | |
368 | { | |
2cca9ebf SA |
369 | GlobalSettings settings; |
370 | settings.undo_tracked_changes(); | |
371 | ||
bf9f1268 SA |
372 | QDialog::reject(); |
373 | } | |
374 | ||
b14db788 SA |
375 | void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous) |
376 | { | |
377 | if (!current) | |
378 | current = previous; | |
379 | ||
380 | pages->setCurrentIndex(page_list->row(current)); | |
381 | } | |
382 | ||
e91fb166 | 383 | void Settings::on_view_zoomToFitDuringAcq_changed(int state) |
bf9f1268 SA |
384 | { |
385 | GlobalSettings settings; | |
e91fb166 | 386 | settings.setValue(GlobalSettings::Key_View_ZoomToFitDuringAcq, state ? true : false); |
bf9f1268 SA |
387 | } |
388 | ||
28ceff25 SA |
389 | void Settings::on_view_zoomToFitAfterAcq_changed(int state) |
390 | { | |
391 | GlobalSettings settings; | |
392 | settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false); | |
393 | } | |
394 | ||
bf9f1268 SA |
395 | void Settings::on_view_colouredBG_changed(int state) |
396 | { | |
397 | GlobalSettings settings; | |
398 | settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false); | |
399 | } | |
400 | ||
87a97d8a SA |
401 | void Settings::on_view_stickyScrolling_changed(int state) |
402 | { | |
403 | GlobalSettings settings; | |
404 | settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false); | |
405 | } | |
406 | ||
051ba3b3 UH |
407 | void Settings::on_view_showSamplingPoints_changed(int state) |
408 | { | |
409 | GlobalSettings settings; | |
410 | settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false); | |
411 | } | |
87a97d8a | 412 | |
8ad61f40 UH |
413 | void Settings::on_view_showAnalogMinorGrid_changed(int state) |
414 | { | |
415 | GlobalSettings settings; | |
416 | settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false); | |
417 | } | |
418 | ||
1cc1c8de SA |
419 | void Settings::on_dec_initialStateConfigurable_changed(int state) |
420 | { | |
421 | GlobalSettings settings; | |
422 | settings.setValue(GlobalSettings::Key_Dec_InitialStateConfigurable, state ? true : false); | |
423 | } | |
424 | ||
bf9f1268 SA |
425 | } // namespace dialogs |
426 | } // namespace pv |