X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fsignal.cpp;h=59817eba2c334fcad882d296f5f0a4ac158e7d17;hp=48e47f27aa9a49304dddc6d1feef879463183cf4;hb=f4e57597347e47a4ea58fbdc7b0a22e07f1c0ede;hpb=b47d951efad3b51674e5af2fcfc29526cad6697f diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 48e47f27..59817eba 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -20,158 +20,170 @@ #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" -const int Signal::LabelHitPadding = 2; -const int Signal::LabelHighlightRadius = 6; +#include "signal.hpp" +#include "view.hpp" -const QPen Signal::SignalAxisPen(QColor(128, 128, 128, 64)); +using std::shared_ptr; +using std::make_shared; -Signal::Signal(QString name) : - _name(name), - _v_offset(0), - _selected(false) +namespace pv { +namespace views { +namespace TraceView { + +const char *const ChannelNames[] = { + "CLK", + "DATA", + "IN", + "OUT", + "RST", + "TX", + "RX", + "EN", + "SCLK", + "MOSI", + "MISO", + "/SS", + "SDA", + "SCL" +}; + +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(base_); -QString Signal::get_name() const -{ - return _name; + connect(base_.get(), SIGNAL(enabled_changed(bool)), + this, SLOT(on_enabled_changed(bool))); } void Signal::set_name(QString name) { - _name = name; + Trace::set_name(name); + + if (name != name_widget_->currentText()) + name_widget_->setEditText(name); } -QColor Signal::get_colour() const +bool Signal::enabled() const { - return _colour; + return base_->enabled(); } -void Signal::set_colour(QColor colour) +shared_ptr Signal::base() const { - _colour = colour; + return base_; } -int Signal::get_v_offset() const +void Signal::save_settings(QSettings &settings) const { - return _v_offset; + (void)settings; } -void Signal::set_v_offset(int v_offset) +void Signal::restore_settings(QSettings &settings) { - _v_offset = v_offset; + (void)settings; } -bool Signal::selected() const +const ViewItemOwner::item_list& Signal::child_items() const { - return _selected; + return items_; } -void Signal::select(bool select) +void Signal::paint_back(QPainter &p, const ViewItemPaintParams &pp) { - _selected = select; + 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); - - 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(QPen(QApplication::palette().brush( - QPalette::Highlight), LabelHighlightRadius, - Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - p.setBrush(Qt::transparent); - p.drawPolygon(points, countof(points)); + name_widget_ = new QComboBox(parent); + name_widget_->setEditable(true); + name_widget_->setCompleter(nullptr); + + for (unsigned int i = 0; i < countof(ChannelNames); i++) + name_widget_->insertItem(i, ChannelNames[i]); + + const int index = name_widget_->findText(base_->name(), Qt::MatchExactly); + + if (index == -1) { + name_widget_->insertItem(0, base_->name()); + name_widget_->setCurrentIndex(0); + } else { + name_widget_->setCurrentIndex(index); } - p.setPen(Qt::transparent); - p.setBrush(hover ? colour.lighter() : colour); - p.drawPolygon(points, countof(points)); + connect(name_widget_, SIGNAL(editTextChanged(const QString&)), + this, SLOT(on_nameedit_changed(const QString&))); - p.setPen(colour.lighter()); - p.setBrush(Qt::transparent); - p.drawPolygon(highlight_points, countof(highlight_points)); + form->addRow(tr("Name"), name_widget_); - p.setPen(colour.darker()); - p.setBrush(Qt::transparent); - p.drawPolygon(points, countof(points)); + add_colour_option(parent, form); +} + +QMenu* Signal::create_context_menu(QWidget *parent) +{ + QMenu *const menu = Trace::create_context_menu(parent); + + menu->addSeparator(); - // Paint the text - p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white); - p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name); + 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; } -bool Signal::pt_in_label_rect(int y, int left, int right, - const QPoint &point) +void Signal::delete_pressed() { - (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); + on_disable(); } -void Signal::paint_axis(QPainter &p, int y, int left, int right) +void Signal::on_name_changed(const QString &text) { - p.setPen(SignalAxisPen); - p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f)); + // 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); } -void Signal::compute_text_size(QPainter &p) +void Signal::on_disable() { - _text_size = QSize( - p.boundingRect(QRectF(), 0, _name).width(), - p.boundingRect(QRectF(), 0, "Tg").height()); + base_->set_enabled(false); } -QRectF Signal::get_label_rect(int y, int right) +void Signal::on_enabled_changed(bool enabled) { - 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()); + (void)enabled; + + if (owner_) + owner_->extents_changed(true, true); } -} // namespace view +} // namespace TraceView +} // namespace views } // namespace pv