X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdialogs%2Fsettings.cpp;h=0104b7c9e32f3de4c146c52ab6326e7fb8b68b9d;hp=d443935efb765e2c88553b3540f6d6dc90e2f785;hb=d008cab11b7508601e793d47e53a87be9972aed1;hpb=2cca9ebfdc367aa8e4651cf063f0cdea8fccb798 diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index d443935e..0104b7c9 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -17,40 +17,95 @@ * along with this program; if not, see . */ -#include "settings.hpp" -#include "pv/globalsettings.hpp" - +#include #include #include #include #include -#include +#include +#include +#include +#include +#include #include +#include "settings.hpp" + +#include "pv/devicemanager.hpp" +#include "pv/globalsettings.hpp" + +#include + +#ifdef ENABLE_DECODE +#include +#endif + +using std::shared_ptr; + namespace pv { namespace dialogs { -Settings::Settings(QWidget *parent) : - QDialog(parent, 0) +Settings::Settings(DeviceManager &device_manager, QWidget *parent) : + QDialog(parent, nullptr), + device_manager_(device_manager) { - QTabWidget *tab_stack = new QTabWidget(this); - tab_stack->addTab(get_view_settings_form(tab_stack), tr("&Views")); + const int icon_size = 64; + + resize(600, 400); + + page_list = new QListWidget; + page_list->setViewMode(QListView::IconMode); + page_list->setIconSize(QSize(icon_size, icon_size)); + page_list->setMovement(QListView::Static); + page_list->setMaximumWidth(icon_size + (icon_size / 2)); + page_list->setSpacing(12); + + pages = new QStackedWidget; + create_pages(); + page_list->setCurrentIndex(page_list->model()->index(0, 0)); + + QHBoxLayout *tab_layout = new QHBoxLayout; + tab_layout->addWidget(page_list); + tab_layout->addWidget(pages, Qt::AlignLeft); QDialogButtonBox *button_box = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel); QVBoxLayout* root_layout = new QVBoxLayout(this); - root_layout->addWidget(tab_stack); + root_layout->addLayout(tab_layout); root_layout->addWidget(button_box); connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); connect(button_box, SIGNAL(rejected()), this, SLOT(reject())); + connect(page_list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), + this, SLOT(on_page_changed(QListWidgetItem*, QListWidgetItem*))); // Start to record changes GlobalSettings settings; settings.start_tracking(); } +void Settings::create_pages() +{ + // View page + pages->addWidget(get_view_settings_form(pages)); + + QListWidgetItem *viewButton = new QListWidgetItem(page_list); + viewButton->setIcon(QIcon(":/icons/settings-views.svg")); + viewButton->setText(tr("Views")); + viewButton->setTextAlignment(Qt::AlignHCenter); + viewButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + // About page + pages->addWidget(get_about_page(pages)); + + QListWidgetItem *aboutButton = new QListWidgetItem(page_list); + aboutButton->setIcon(QIcon(":/icons/information.svg")); + aboutButton->setText(tr("About")); + aboutButton->setTextAlignment(Qt::AlignHCenter); + aboutButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); +} + QWidget *Settings::get_view_settings_form(QWidget *parent) const { GlobalSettings settings; @@ -68,16 +123,138 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const QCheckBox *coloured_bg_cb = new QCheckBox(); coloured_bg_cb->setChecked(settings.value(GlobalSettings::Key_View_ColouredBG).toBool()); connect(coloured_bg_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_colouredBG_changed(int))); - trace_view_layout->addRow(tr("Use &coloured trace background"), coloured_bg_cb); + trace_view_layout->addRow(tr("Use coloured trace &background"), coloured_bg_cb); QCheckBox *always_zoom_to_fit_cb = new QCheckBox(); always_zoom_to_fit_cb->setChecked(settings.value(GlobalSettings::Key_View_AlwaysZoomToFit).toBool()); connect(always_zoom_to_fit_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_alwaysZoomToFit_changed(int))); - trace_view_layout->addRow(tr("Always zoom-to-&fit during capture"), always_zoom_to_fit_cb); + trace_view_layout->addRow(tr("Constantly perform &zoom-to-fit during capture"), always_zoom_to_fit_cb); + + QCheckBox *sticky_scrolling_cb = new QCheckBox(); + sticky_scrolling_cb->setChecked(settings.value(GlobalSettings::Key_View_StickyScrolling).toBool()); + connect(sticky_scrolling_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_stickyScrolling_changed(int))); + trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), sticky_scrolling_cb); + + QCheckBox *show_sampling_points_cb = new QCheckBox(); + show_sampling_points_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool()); + connect(show_sampling_points_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showSamplingPoints_changed(int))); + trace_view_layout->addRow(tr("Show data &sampling points"), show_sampling_points_cb); + + QCheckBox *show_analog_minor_grid_cb = new QCheckBox(); + show_analog_minor_grid_cb->setChecked(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool()); + connect(show_analog_minor_grid_cb, SIGNAL(stateChanged(int)), this, SLOT(on_view_showAnalogMinorGrid_changed(int))); + trace_view_layout->addRow(tr("Show analog minor grid in addition to vdiv grid"), show_analog_minor_grid_cb); return form; } +#ifdef ENABLE_DECODE +static gint sort_pds(gconstpointer a, gconstpointer b) +{ + const struct srd_decoder *sda, *sdb; + + sda = (const struct srd_decoder *)a; + sdb = (const struct srd_decoder *)b; + return strcmp(sda->id, sdb->id); +} +#endif + +QWidget *Settings::get_about_page(QWidget *parent) const +{ +#ifdef ENABLE_DECODE + struct srd_decoder *dec; +#endif + + QLabel *icon = new QLabel(); + icon->setPixmap(QPixmap(QString::fromUtf8(":/icons/sigrok-logo-notext.svg"))); + + /* Setup the version field */ + QLabel *version_info = new QLabel(); + version_info->setText(tr("%1 %2
%3
%4") + .arg(QApplication::applicationName(), + QApplication::applicationVersion(), + tr("GNU GPL, version 3 or later"), + QApplication::organizationDomain())); + version_info->setOpenExternalLinks(true); + + shared_ptr context = device_manager_.context(); + + QString s; + + s.append(""); + + s.append(""); + + /* Library info */ + s.append(""); + s.append(QString("") + .arg(QString("Qt"), qVersion())); + s.append(QString("") + .arg(QString("libsigrok"), sr_package_version_string_get(), sr_lib_version_string_get())); +#ifdef ENABLE_DECODE + s.append(QString("") + .arg(QString("libsigrokdecode"), srd_package_version_string_get(), srd_lib_version_string_get())); +#endif + + /* Set up the supported field */ + s.append(""); + for (auto entry : context->drivers()) { + s.append(QString("") + .arg(QString::fromUtf8(entry.first.c_str()), + QString::fromUtf8(entry.second->long_name().c_str()))); + } + + s.append(""); + for (auto entry : context->input_formats()) { + s.append(QString("") + .arg(QString::fromUtf8(entry.first.c_str()), + QString::fromUtf8(entry.second->description().c_str()))); + } + + s.append(""); + for (auto entry : context->output_formats()) { + s.append(QString("") + .arg(QString::fromUtf8(entry.first.c_str()), + QString::fromUtf8(entry.second->description().c_str()))); + } + +#ifdef ENABLE_DECODE + s.append(""); + GSList *sl = g_slist_copy((GSList *)srd_decoder_list()); + sl = g_slist_sort(sl, sort_pds); + for (const GSList *l = sl; l; l = l->next) { + dec = (struct srd_decoder *)l->data; + s.append(QString("") + .arg(QString::fromUtf8(dec->id), + QString::fromUtf8(dec->longname))); + } + g_slist_free(sl); +#endif + + s.append("
" + + tr("Used libraries:") + "
%1%2
%1%2 (lib version %3)
%1%2 (lib version %3)
" + + tr("Supported hardware drivers:") + "
%1%2
" + + tr("Supported input formats:") + "
%1%2
" + + tr("Supported output formats:") + "
%1%2
" + + tr("Supported protocol decoders:") + "
%1%2
"); + + QTextDocument *supported_doc = new QTextDocument(); + supported_doc->setHtml(s); + + QTextBrowser *support_list = new QTextBrowser(); + support_list->setDocument(supported_doc); + + QGridLayout *layout = new QGridLayout(); + layout->addWidget(icon, 0, 0, 1, 1); + layout->addWidget(version_info, 0, 1, 1, 1); + layout->addWidget(support_list, 1, 1, 1, 1); + + QWidget *page = new QWidget(parent); + page->setLayout(layout); + + return page; +} + void Settings::accept() { GlobalSettings settings; @@ -94,6 +271,14 @@ void Settings::reject() QDialog::reject(); } +void Settings::on_page_changed(QListWidgetItem *current, QListWidgetItem *previous) +{ + if (!current) + current = previous; + + pages->setCurrentIndex(page_list->row(current)); +} + void Settings::on_view_alwaysZoomToFit_changed(int state) { GlobalSettings settings; @@ -106,5 +291,23 @@ void Settings::on_view_colouredBG_changed(int state) settings.setValue(GlobalSettings::Key_View_ColouredBG, state ? true : false); } +void Settings::on_view_stickyScrolling_changed(int state) +{ + GlobalSettings settings; + settings.setValue(GlobalSettings::Key_View_StickyScrolling, state ? true : false); +} + +void Settings::on_view_showSamplingPoints_changed(int state) +{ + GlobalSettings settings; + settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, state ? true : false); +} + +void Settings::on_view_showAnalogMinorGrid_changed(int state) +{ + GlobalSettings settings; + settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, state ? true : false); +} + } // namespace dialogs } // namespace pv