From 204bae4548c295cae1d88fc4eae027a17e5a58a7 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 30 Nov 2013 16:02:45 +0000 Subject: [PATCH] Created DecoderGroupBox widget --- CMakeLists.txt | 2 ++ icons/decoder-delete.svg | 17 +++++++++ pulseview.qrc | 1 + pv/view/decodetrace.cpp | 14 +++++--- pv/widgets/decodergroupbox.cpp | 63 ++++++++++++++++++++++++++++++++++ pv/widgets/decodergroupbox.h | 51 +++++++++++++++++++++++++++ test/CMakeLists.txt | 2 ++ 7 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 icons/decoder-delete.svg create mode 100644 pv/widgets/decodergroupbox.cpp create mode 100644 pv/widgets/decodergroupbox.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5072c45..443dea6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,7 @@ set(pulseview_SOURCES pv/view/decode/annotation.cpp pv/widgets/colourbutton.cpp pv/widgets/colourpopup.cpp + pv/widgets/decodergroupbox.cpp pv/widgets/decodermenu.cpp pv/widgets/popup.cpp pv/widgets/popuptoolbutton.cpp @@ -181,6 +182,7 @@ set(pulseview_HEADERS pv/view/viewport.h pv/widgets/colourbutton.h pv/widgets/colourpopup.h + pv/widgets/decodergroupbox.h pv/widgets/decodermenu.h pv/widgets/popup.h pv/widgets/popuptoolbutton.h diff --git a/icons/decoder-delete.svg b/icons/decoder-delete.svg new file mode 100644 index 0000000..b9db4ea --- /dev/null +++ b/icons/decoder-delete.svg @@ -0,0 +1,17 @@ + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/pulseview.qrc b/pulseview.qrc index a1577d6..a7108b4 100644 --- a/pulseview.qrc +++ b/pulseview.qrc @@ -2,6 +2,7 @@ icons/application-exit.png icons/configure.png + icons/decoder-delete.svg icons/document-open.png icons/probes.svg icons/sigrok-logo-notext.png diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index d3d10b6..3e78e6e 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -41,6 +41,7 @@ extern "C" { #include #include #include +#include #include using namespace boost; @@ -207,7 +208,10 @@ void DecodeTrace::create_decoder_form(shared_ptr &dec, const srd_decoder *const decoder = dec->decoder(); assert(decoder); - form->addRow(new QLabel(tr("

%1

").arg(decoder->name), parent)); + pv::widgets::DecoderGroupBox *const group = + new pv::widgets::DecoderGroupBox(decoder->name); + QFormLayout *const decoder_form = new QFormLayout; + group->add_layout(decoder_form); // Add the mandatory probes for(probe = decoder->probes; probe; probe = probe->next) { @@ -216,7 +220,7 @@ void DecodeTrace::create_decoder_form(shared_ptr &dec, QComboBox *const combo = create_probe_selector(parent, dec, p); connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_probe_selected(int))); - form->addRow(tr("%1 (%2) *") + decoder_form->addRow(tr("%1 (%2) *") .arg(p->name).arg(p->desc), combo); const ProbeSelector s = {combo, dec, p}; @@ -230,7 +234,7 @@ void DecodeTrace::create_decoder_form(shared_ptr &dec, QComboBox *const combo = create_probe_selector(parent, dec, p); connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_probe_selected(int))); - form->addRow(tr("%1 (%2)") + decoder_form->addRow(tr("%1 (%2)") .arg(p->name).arg(p->desc), combo); const ProbeSelector s = {combo, dec, p}; @@ -240,9 +244,11 @@ void DecodeTrace::create_decoder_form(shared_ptr &dec, // Add the options shared_ptr binding( new prop::binding::DecoderOptions(_decoder_stack, dec)); - binding->add_properties_to_form(form, true); + binding->add_properties_to_form(decoder_form, true); _bindings.push_back(binding); + + form->addRow(group); } QComboBox* DecodeTrace::create_probe_selector( diff --git a/pv/widgets/decodergroupbox.cpp b/pv/widgets/decodergroupbox.cpp new file mode 100644 index 0000000..4cf6a08 --- /dev/null +++ b/pv/widgets/decodergroupbox.cpp @@ -0,0 +1,63 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "decodergroupbox.h" + +#include +#include +#include +#include +#include + +#include + +namespace pv { +namespace widgets { + +DecoderGroupBox::DecoderGroupBox(QString title, QWidget *parent) : + QWidget(parent), + _layout(new QGridLayout) +{ + _layout->setContentsMargins(0, 0, 0, 0); + setLayout(_layout); + + _layout->addWidget(new QLabel(QString("

%1

").arg(title)), + 0, 0); + _layout->setColumnStretch(0, 1); + + QToolBar *const toolbar = new QToolBar; + toolbar->setIconSize(QSize(16, 16)); + _layout->addWidget(toolbar, 0, 1); + + QAction *const delete_action = new QAction( + QIcon(":/icons/decoder-delete.svg"), tr("Delete"), this); + connect(delete_action, SIGNAL(triggered()), + this, SIGNAL(delete_decoder())); + toolbar->addAction(delete_action); +} + +void DecoderGroupBox::add_layout(QLayout *layout) +{ + assert(layout); + _layout->addLayout(layout, 1, 0, 1, 2); +} + +} // widgets +} // pv diff --git a/pv/widgets/decodergroupbox.h b/pv/widgets/decodergroupbox.h new file mode 100644 index 0000000..7b6bc93 --- /dev/null +++ b/pv/widgets/decodergroupbox.h @@ -0,0 +1,51 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PULSEVIEW_PV_WIDGETS_DECODERGROUPBox_H +#define PULSEVIEW_PV_WIDGETS_DECODERGROUPBOX_H + +#include + +class QGridLayout; +class QToolBar; + +namespace pv { +namespace widgets { + +class DecoderGroupBox : public QWidget +{ + Q_OBJECT + +public: + DecoderGroupBox(QString title, QWidget *parent = NULL); + + void add_layout(QLayout *layout); + +signals: + void delete_decoder(); + +private: + QGridLayout *const _layout; +}; + +} // widgets +} // pv + +#endif // PULSEVIEW_PV_WIDGETS_DECODERGROUPBOX_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f871504..752e809 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -70,6 +70,7 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/view/decode/annotation.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/colourbutton.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/colourpopup.cpp + ${PROJECT_SOURCE_DIR}/pv/widgets/decodergroupbox.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/decodermenu.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/popup.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/wellarray.cpp @@ -100,6 +101,7 @@ set(pulseview_TEST_HEADERS ${PROJECT_SOURCE_DIR}/pv/view/viewport.h ${PROJECT_SOURCE_DIR}/pv/widgets/colourbutton.h ${PROJECT_SOURCE_DIR}/pv/widgets/colourpopup.h + ${PROJECT_SOURCE_DIR}/pv/widgets/decodergroupbox.h ${PROJECT_SOURCE_DIR}/pv/widgets/decodermenu.h ${PROJECT_SOURCE_DIR}/pv/widgets/popup.h ${PROJECT_SOURCE_DIR}/pv/widgets/wellarray.h -- 2.30.2