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/>.
20 #include <QApplication>
22 #include <QDialogButtonBox>
23 #include <QFormLayout>
25 #include <QHBoxLayout>
28 #include <QTextBrowser>
29 #include <QTextDocument>
30 #include <QVBoxLayout>
32 #include "settings.hpp"
34 #include "pv/devicemanager.hpp"
35 #include "pv/globalsettings.hpp"
37 #include <libsigrokcxx/libsigrokcxx.hpp>
40 #include <libsigrokdecode/libsigrokdecode.h>
46 Settings::Settings(DeviceManager &device_manager, QWidget *parent) :
47 QDialog(parent, nullptr),
48 device_manager_(device_manager)
50 const int icon_size = 64;
54 page_list = new QListWidget;
55 page_list->setViewMode(QListView::IconMode);
56 page_list->setIconSize(QSize(icon_size, icon_size));
57 page_list->setMovement(QListView::Static);
58 page_list->setMaximumWidth(icon_size + icon_size/2);
59 page_list->setSpacing(12);
61 pages = new QStackedWidget;
64 QHBoxLayout *tab_layout = new QHBoxLayout;
65 tab_layout->addWidget(page_list);
66 tab_layout->addWidget(pages, Qt::AlignLeft);
68 QDialogButtonBox *button_box = new QDialogButtonBox(
69 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
71 QVBoxLayout* root_layout = new QVBoxLayout(this);
72 root_layout->addLayout(tab_layout);
73 root_layout->addWidget(button_box);
75 connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
76 connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
77 connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
78 this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*)));
80 // Start to record changes
81 GlobalSettings settings;
82 settings.start_tracking();
85 void Settings::create_pages()
88 pages->addWidget(get_view_settings_form(pages));
90 QListWidgetItem *viewButton = new QListWidgetItem(page_list);
91 viewButton->setIcon(QIcon(":/icons/sigrok-logo-notext.svg"));
92 viewButton->setText(tr("Views"));
93 viewButton->setTextAlignment(Qt::AlignHCenter);
94 viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
97 pages->addWidget(get_about_page(pages));
99 QListWidgetItem *aboutButton = new QListWidgetItem(page_list);
100 aboutButton->setIcon(QIcon(":/icons/information.svg"));
101 aboutButton->setText(tr("About"));
102 aboutButton->setTextAlignment(Qt::AlignHCenter);
103 aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
106 QWidget *Settings::get_view_settings_form(QWidget *parent) const
108 GlobalSettings settings;
110 QWidget *form = new QWidget(parent);
111 QVBoxLayout *form_layout = new QVBoxLayout(form);
113 // Trace view settings
114 QGroupBox *trace_view_group = new QGroupBox(tr("Trace View"));
115 form_layout->addWidget(trace_view_group);
117 QFormLayout *trace_view_layout = new QFormLayout();
118 trace_view_group->setLayout(trace_view_layout);
120 QCheckBox *coloured_bg_cb = new QCheckBox();
121 coloured_bg_cb->setChecked(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
122 connect(coloured_bg_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_colouredBG_changed(int)));
123 trace_view_layout->addRow(tr("Use coloured trace &background"), coloured_bg_cb);
125 QCheckBox *always_zoom_to_fit_cb = new QCheckBox();
126 always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool());
127 connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int)));
128 trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during capture"), always_zoom_to_fit_cb);
130 QCheckBox *sticky_scrolling_cb = new QCheckBox();
131 sticky_scrolling_cb->setChecked(settings.value(GlobalSettings::Key_View_StickyScrolling).toBool());
132 connect(sticky_scrolling_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_stickyScrolling_changed(int)));
133 trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), sticky_scrolling_cb);
138 QWidget *Settings::get_about_page(QWidget *parent) const
141 struct srd_decoder *dec;
144 QLabel *icon = new QLabel();
145 icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/sigrok-logo-notext.svg")));
147 /* Setup the version field */
148 QLabel *version_info = new QLabel();
149 version_info->setText(tr("%1 %2<br />%3<br /><a href=\"http://%4\">%4</a>")
150 .arg(QApplication::applicationName(),
151 QApplication::applicationVersion(),
152 tr("GNU GPL, version 3 or later"),
153 QApplication::organizationDomain()));
154 version_info->setOpenExternalLinks(true);
156 std::shared_ptr<sigrok::Context> context = device_manager_.context();
161 /* Set up the supported field */
162 s.append("<tr><td colspan=\"2\"><b>" +
163 tr("Supported hardware drivers:") +
165 for (auto entry : context->drivers()) {
166 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
167 .arg(QString::fromUtf8(entry.first.c_str()),
168 QString::fromUtf8(entry.second->long_name().c_str())));
171 s.append("<tr><td colspan=\"2\"><b>" +
172 tr("Supported input formats:") +
174 for (auto entry : context->input_formats()) {
175 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
176 .arg(QString::fromUtf8(entry.first.c_str()),
177 QString::fromUtf8(entry.second->description().c_str())));
180 s.append("<tr><td colspan=\"2\"><b>" +
181 tr("Supported output formats:") +
183 for (auto entry : context->output_formats()) {
184 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
185 .arg(QString::fromUtf8(entry.first.c_str()),
186 QString::fromUtf8(entry.second->description().c_str())));
190 s.append("<tr><td colspan=\"2\"><b>" +
191 tr("Supported protocol decoders:") +
193 for (const GSList *l = srd_decoder_list(); l; l = l->next) {
194 dec = (struct srd_decoder *)l->data;
195 s.append(QString("<tr><td><i>%1</i></td><td>%2</td></tr>")
196 .arg(QString::fromUtf8(dec->id),
197 QString::fromUtf8(dec->longname)));
201 s.append("</table>");
203 QTextDocument *supported_doc = new QTextDocument();
204 supported_doc->setHtml(s);
206 QTextBrowser *support_list = new QTextBrowser();
207 support_list->setDocument(supported_doc);
209 QGridLayout *layout = new QGridLayout();
210 layout->addWidget(icon, 0, 0, 1, 1);
211 layout->addWidget(version_info, 0, 1, 1, 1);
212 layout->addWidget(support_list, 1, 1, 1, 1);
214 QWidget *page = new QWidget(parent);
215 page->setLayout(layout);
220 void Settings::accept()
222 GlobalSettings settings;
223 settings.stop_tracking();
228 void Settings::reject()
230 GlobalSettings settings;
231 settings.undo_tracked_changes();
236 void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous)
241 pages->setCurrentIndex(page_list->row(current));
244 void Settings::on_view_alwaysZoomToFit_changed(int state)
246 GlobalSettings settings;
247 settings.setValue(GlobalSettings::Key_View_AlwaysZoomToFit, state ? true : false);
250 void Settings::on_view_colouredBG_changed(int state)
252 GlobalSettings settings;
253 settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false);
256 void Settings::on_view_stickyScrolling_changed(int state)
258 GlobalSettings settings;
259 settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false);
263 } // namespace dialogs