2 * This file is part of the PulseView project.
4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
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.
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.
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/>.
23 #include <boost/version.hpp>
25 #include <QApplication>
27 #include <QDialogButtonBox>
28 #include <QFormLayout>
30 #include <QHBoxLayout>
33 #include <QTextBrowser>
34 #include <QTextDocument>
35 #include <QVBoxLayout>
37 #include "settings.hpp"
39 #include "pv/devicemanager.hpp"
40 #include "pv/globalsettings.hpp"
42 #include <libsigrokcxx/libsigrokcxx.hpp>
45 #include <libsigrokdecode/libsigrokdecode.h>
48 using std::shared_ptr;
53 Settings::Settings(DeviceManager &device_manager, QWidget *parent) :
54 QDialog(parent, nullptr),
55 device_manager_(device_manager)
57 const int icon_size = 64;
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);
65 page_list->setMaximumWidth(icon_size + (icon_size / 2));
66 page_list->setSpacing(12);
68 pages = new QStackedWidget;
70 page_list->setCurrentIndex(page_list->model()->index(0, 0));
72 QHBoxLayout *tab_layout = new QHBoxLayout;
73 tab_layout->addWidget(page_list);
74 tab_layout->addWidget(pages, Qt::AlignLeft);
76 QDialogButtonBox *button_box = new QDialogButtonBox(
77 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
79 QVBoxLayout* root_layout = new QVBoxLayout(this);
80 root_layout->addLayout(tab_layout);
81 root_layout->addWidget(button_box);
83 connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
84 connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
85 connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
86 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
88 // Start to record changes
89 GlobalSettings settings;
90 settings.start_tracking();
93 void Settings::create_pages()
96 pages->addWidget(get_view_settings_form(pages));
98 QListWidgetItem *viewButton = new QListWidgetItem(page_list);
99 viewButton->setIcon(QIcon(":/icons/settings-views.svg"));
100 viewButton->setText(tr("Views"));
101 viewButton->setTextAlignment(Qt::AlignHCenter);
102 viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
105 pages->addWidget(get_about_page(pages));
107 QListWidgetItem *aboutButton = new QListWidgetItem(page_list);
108 aboutButton->setIcon(QIcon(":/icons/information.svg"));
109 aboutButton->setText(tr("About"));
110 aboutButton->setTextAlignment(Qt::AlignHCenter);
111 aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
114 QWidget *Settings::get_view_settings_form(QWidget *parent) const
116 GlobalSettings settings;
118 QWidget *form = new QWidget(parent);
119 QVBoxLayout *form_layout = new QVBoxLayout(form);
121 // Trace view settings
122 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
123 form_layout->addWidget(trace_view_group);
125 QFormLayout *trace_view_layout = new QFormLayout();
126 trace_view_group->setLayout(trace_view_layout);
128 QCheckBox *coloured_bg_cb = new QCheckBox();
129 coloured_bg_cb->setChecked(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
130 connect(coloured_bg_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_colouredBG_changed(int)));
131 trace_view_layout->addRow(tr("Use coloured trace &background"), coloured_bg_cb);
133 QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
134 always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
135 connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
136 trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during capture"), always_zoom_to_fit_cb);
138 QCheckBox *sticky_scrolling_cb = new QCheckBox();
139 sticky_scrolling_cb->setChecked(settings.value(GlobalSettings::Key_View_StickyScrolling).toBool());
140 connect(sticky_scrolling_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_stickyScrolling_changed(int)));
141 trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), sticky_scrolling_cb);
143 QCheckBox *show_sampling_points_cb = new QCheckBox();
144 show_sampling_points_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool());
145 connect(show_sampling_points_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showSamplingPoints_changed(int)));
146 trace_view_layout->addRow(tr("Show data &sampling points"), show_sampling_points_cb);
148 QCheckBox *show_analog_minor_grid_cb = new QCheckBox();
149 show_analog_minor_grid_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool());
150 connect(show_analog_minor_grid_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showAnalogMinorGrid_changed(int)));
151 trace_view_layout->addRow(tr("Show analog minor grid in addition to vdiv grid"), show_analog_minor_grid_cb);
157 static gint sort_pds(gconstpointer a, gconstpointer b)
159 const struct srd_decoder *sda, *sdb;
161 sda = (const struct srd_decoder *)a;
162 sdb = (const struct srd_decoder *)b;
163 return strcmp(sda->id, sdb->id);
167 QWidget *Settings::get_about_page(QWidget *parent) const
170 struct srd_decoder *dec;
173 QLabel *icon = new QLabel();
174 icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/sigrok-logo-notext.svg")));
176 /* Setup the version field */
177 QLabel *version_info = new QLabel();
178 version_info->setText(tr("%1 %2<br />%3<br /><a href=\"http://%4\">%4</a>")
179 .arg(QApplication::applicationName(),
180 QApplication::applicationVersion(),
181 tr("GNU GPL, version 3 or later"),
182 QApplication::organizationDomain()));
183 version_info->setOpenExternalLinks(true);
185 shared_ptr<sigrok::Context> context = device_manager_.context();
189 s.append("<style type=\"text/css\"> tr .id { white-space: pre; padding-right: 5px; } </style>");
194 s.append("<tr><td colspan=\"2\"><b>" +
195 tr("Libraries and features:") + "</b></td></tr>");
197 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
198 .arg(QString("Qt"), qVersion()));
199 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
200 .arg(QString("glibmm"), PV_GLIBMM_VERSION));
201 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
202 .arg(QString("Boost"), BOOST_LIB_VERSION));
204 s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
205 .arg(QString("libsigrok"), SR_PACKAGE_VERSION_STRING,
206 SR_LIB_VERSION_STRING, sr_package_version_string_get(),
207 sr_lib_version_string_get()));
209 GSList *l_orig = sr_buildinfo_libs_get();
210 for (GSList *l = l_orig; l; l = l->next) {
211 GSList *m = (GSList *)l->data;
212 const char *lib = (const char *)m->data;
213 const char *version = (const char *)m->next->data;
214 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
215 .arg(QString(lib), QString(version)));
216 g_slist_free_full(m, g_free);
218 g_slist_free(l_orig);
220 char *host = sr_buildinfo_host_get();
221 s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
222 .arg(QString(host)));
225 char *scpi_backends = sr_buildinfo_scpi_backends_get();
226 s.append(QString("<tr><td><i>- SCPI backends</i></td><td>%1</td></tr>")
227 .arg(QString(scpi_backends)));
228 g_free(scpi_backends);
231 s.append(QString("<tr><td><i>%1</i></td><td>%2/%3 (rt: %4/%5)</td></tr>")
232 .arg(QString("libsigrokdecode"), SRD_PACKAGE_VERSION_STRING,
233 SRD_LIB_VERSION_STRING, srd_package_version_string_get(),
234 srd_lib_version_string_get()));
236 l_orig = srd_buildinfo_libs_get();
237 for (GSList *l = l_orig; l; l = l->next) {
238 GSList *m = (GSList *)l->data;
239 const char *lib = (const char *)m->data;
240 const char *version = (const char *)m->next->data;
241 s.append(QString("<tr><td><i>- %1</i></td><td>%2</td></tr>")
242 .arg(QString(lib), QString(version)));
243 g_slist_free_full(m, g_free);
245 g_slist_free(l_orig);
247 host = srd_buildinfo_host_get();
248 s.append(QString("<tr><td><i>- Host</i></td><td>%1</td></tr>")
249 .arg(QString(host)));
253 /* Set up the supported field */
254 s.append("<tr><td colspan=\"2\"></td></tr>");
255 s.append("<tr><td colspan=\"2\"><b>" +
256 tr("Supported hardware drivers:") + "</b></td></tr>");
257 for (auto entry : context->drivers()) {
258 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
259 .arg(QString::fromUtf8(entry.first.c_str()),
260 QString::fromUtf8(entry.second->long_name().c_str())));
263 s.append("<tr><td colspan=\"2\"></td></tr>");
264 s.append("<tr><td colspan=\"2\"><b>" +
265 tr("Supported input formats:") + "</b></td></tr>");
266 for (auto entry : context->input_formats()) {
267 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
268 .arg(QString::fromUtf8(entry.first.c_str()),
269 QString::fromUtf8(entry.second->description().c_str())));
272 s.append("<tr><td colspan=\"2\"></td></tr>");
273 s.append("<tr><td colspan=\"2\"><b>" +
274 tr("Supported output formats:") + "</b></td></tr>");
275 for (auto entry : context->output_formats()) {
276 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
277 .arg(QString::fromUtf8(entry.first.c_str()),
278 QString::fromUtf8(entry.second->description().c_str())));
282 s.append("<tr><td colspan=\"2\"></td></tr>");
283 s.append("<tr><td colspan=\"2\"><b>" +
284 tr("Supported protocol decoders:") + "</b></td></tr>");
285 GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
286 sl = g_slist_sort(sl, sort_pds);
287 for (const GSList *l = sl; l; l = l->next) {
288 dec = (struct srd_decoder *)l->data;
289 s.append(QString("<tr><td class=\"id\"><i>%1</i></td><td>%2</td></tr>")
290 .arg(QString::fromUtf8(dec->id),
291 QString::fromUtf8(dec->longname)));
296 s.append("</table>");
298 QTextDocument *supported_doc = new QTextDocument();
299 supported_doc->setHtml(s);
301 QTextBrowser *support_list = new QTextBrowser();
302 support_list->setDocument(supported_doc);
304 QGridLayout *layout = new QGridLayout();
305 layout->addWidget(icon, 0, 0, 1, 1);
306 layout->addWidget(version_info, 0, 1, 1, 1);
307 layout->addWidget(support_list, 1, 1, 1, 1);
309 QWidget *page = new QWidget(parent);
310 page->setLayout(layout);
315 void Settings::accept()
317 GlobalSettings settings;
318 settings.stop_tracking();
323 void Settings::reject()
325 GlobalSettings settings;
326 settings.undo_tracked_changes();
331 void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
336 pages->setCurrentIndex(page_list->row(current));
339 void Settings::on_view_alwaysZoomToFit_changed(int state)
341 GlobalSettings settings;
342 settings.setValue(GlobalSettings::Key_View_AlwaysZoomToFit, state ? true : false);
345 void Settings::on_view_colouredBG_changed(int state)
347 GlobalSettings settings;
348 settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
351 void Settings::on_view_stickyScrolling_changed(int state)
353 GlobalSettings settings;
354 settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
357 void Settings::on_view_showSamplingPoints_changed(int state)
359 GlobalSettings settings;
360 settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false);
363 void Settings::on_view_showAnalogMinorGrid_changed(int state)
365 GlobalSettings settings;
366 settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false);
369 } // namespace dialogs