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