X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fsignal.cpp;h=ad139f7e4ad21cbbb79a03355aa1917fdfbd2d03;hp=ab1426e0ed08d548e11157cfb074971c422e00f2;hb=3a21afa6;hpb=c0f868521a211747f89ef217ae63404f373d952b diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index ab1426e0..ad139f7e 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -21,28 +21,35 @@ #include #include -#include +#include #include +#include +#include +#include +#include -#include "signal.h" -#include "view.h" +#include -namespace pv { -namespace view { +#include "pv/data/signalbase.hpp" + +#include "signal.hpp" +#include "view.hpp" -const int Signal::LabelHitPadding = 2; +using std::shared_ptr; +using std::make_shared; -const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64)); +namespace pv { +namespace view { -const char *const ProbeNames[] = { +const char *const ChannelNames[] = { "CLK", "DATA", "IN", "OUT", "RST", - "Tx", - "Rx", + "TX", + "RX", "EN", "SCLK", "MOSI", @@ -52,157 +59,128 @@ const char *const ProbeNames[] = { "SCL" }; -Signal::Signal(pv::SigSession &session, const sr_probe *const probe) : - _session(session), - _probe(probe), - _name(probe->name), - _v_offset(0), - _name_action(NULL), - _name_widget(), - _updating_name_widget(false) +Signal::Signal(pv::Session &session, + std::shared_ptr channel) : + Trace(channel), + session_(session), + scale_handle_(make_shared(*this)), + items_({scale_handle_}), + name_widget_(nullptr) { - assert(_probe); + assert(base_); - _name_action.setDefaultWidget(&_name_widget); + connect(base_.get(), SIGNAL(enabled_changed(bool)), + this, SLOT(on_enabled_changed(bool))); +} - _name_widget.setEditable(true); - for(unsigned int i = 0; i < countof(ProbeNames); i++) - _name_widget.insertItem(i, ProbeNames[i]); - _name_widget.setEditText(probe->name); +void Signal::set_name(QString name) +{ + Trace::set_name(name); - connect(&_name_widget, SIGNAL(editTextChanged(const QString&)), - this, SLOT(on_text_changed(const QString&))); + if (name != name_widget_->currentText()) + name_widget_->setEditText(name); } -QString Signal::get_name() const +bool Signal::enabled() const { - return _name; + return base_->enabled(); } -void Signal::set_name(QString name) +shared_ptr Signal::base() const { - _name = name; - _updating_name_widget = true; - _name_widget.setEditText(name); - _updating_name_widget = false; + return base_; } -QColor Signal::get_colour() const +void Signal::save_settings(QSettings &settings) const { - return _colour; + (void)settings; } -void Signal::set_colour(QColor colour) +void Signal::restore_settings(QSettings &settings) { - _colour = colour; + (void)settings; } -int Signal::get_v_offset() const +const ViewItemOwner::item_list& Signal::child_items() const { - return _v_offset; + return items_; } -void Signal::set_v_offset(int v_offset) +void Signal::paint_back(QPainter &p, const ViewItemPaintParams &pp) { - _v_offset = v_offset; + if (base_->enabled()) + Trace::paint_back(p, pp); } -void Signal::paint_label(QPainter &p, int y, int right, bool hover) +void Signal::populate_popup_form(QWidget *parent, QFormLayout *form) { - p.setBrush(_colour); + name_widget_ = new QComboBox(parent); + name_widget_->setEditable(true); + name_widget_->setCompleter(nullptr); - if (!_probe->enabled) - return; + for (unsigned int i = 0; i < countof(ChannelNames); i++) + name_widget_->insertItem(i, ChannelNames[i]); - const QColor colour = get_colour(); - - compute_text_size(p); - const QRectF label_rect = get_label_rect(y, right); - - // Paint the label - const QPointF points[] = { - label_rect.topLeft(), - label_rect.topRight(), - QPointF(right, y), - label_rect.bottomRight(), - label_rect.bottomLeft() - }; - - const QPointF highlight_points[] = { - QPointF(label_rect.left() + 1, label_rect.top() + 1), - QPointF(label_rect.right(), label_rect.top() + 1), - QPointF(right - 1, y), - QPointF(label_rect.right(), label_rect.bottom() - 1), - QPointF(label_rect.left() + 1, label_rect.bottom() - 1) - }; - - if (selected()) { - p.setPen(highlight_pen()); - p.setBrush(Qt::transparent); - p.drawPolygon(points, countof(points)); - } + const int index = name_widget_->findText(base_->name(), Qt::MatchExactly); - p.setPen(Qt::transparent); - p.setBrush(hover ? colour.lighter() : colour); - p.drawPolygon(points, countof(points)); + if (index == -1) { + name_widget_->insertItem(0, base_->name()); + name_widget_->setCurrentIndex(0); + } else { + name_widget_->setCurrentIndex(index); + } - p.setPen(colour.lighter()); - p.setBrush(Qt::transparent); - p.drawPolygon(highlight_points, countof(highlight_points)); + connect(name_widget_, SIGNAL(editTextChanged(const QString&)), + this, SLOT(on_nameedit_changed(const QString&))); - p.setPen(colour.darker()); - p.setBrush(Qt::transparent); - p.drawPolygon(points, countof(points)); + form->addRow(tr("Name"), name_widget_); - // Paint the text - p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white); - p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name); + add_colour_option(parent, form); } -bool Signal::pt_in_label_rect(int y, int left, int right, - const QPoint &point) +QMenu* Signal::create_context_menu(QWidget *parent) { - (void)left; - - const QRectF label = get_label_rect(y, right); - return QRectF( - QPointF(label.left() - LabelHitPadding, - label.top() - LabelHitPadding), - QPointF(right, label.bottom() + LabelHitPadding) - ).contains(point); + QMenu *const menu = Trace::create_context_menu(parent); + + menu->addSeparator(); + + QAction *const disable = new QAction(tr("Disable"), this); + disable->setShortcuts(QKeySequence::Delete); + connect(disable, SIGNAL(triggered()), this, SLOT(on_disable())); + menu->addAction(disable); + + return menu; } -void Signal::paint_axis(QPainter &p, int y, int left, int right) +void Signal::delete_pressed() { - p.setPen(SignalAxisPen); - p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f)); + on_disable(); } -void Signal::compute_text_size(QPainter &p) +void Signal::on_name_changed(const QString &text) { - _text_size = QSize( - p.boundingRect(QRectF(), 0, _name).width(), - p.boundingRect(QRectF(), 0, "Tg").height()); + // On startup, this event is fired when a session restores signal + // names. However, the name widget hasn't yet been created. + if (!name_widget_) + return; + + if (text != name_widget_->currentText()) + name_widget_->setEditText(text); + + Trace::on_name_changed(text); } -QRectF Signal::get_label_rect(int y, int right) +void Signal::on_disable() { - using pv::view::View; - - const QSizeF label_size( - _text_size.width() + View::LabelPadding.width() * 2, - ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2); - const float label_arrow_length = label_size.height() / 2; - return QRectF( - right - label_arrow_length - label_size.width() - 0.5, - y + 0.5f - label_size.height() / 2, - label_size.width(), label_size.height()); + base_->set_enabled(false); } -void Signal::on_text_changed(const QString &text) +void Signal::on_enabled_changed(bool enabled) { - _name = text; - text_changed(); + (void)enabled; + + if (owner_) + owner_->extents_changed(true, true); } } // namespace view