X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fview%2Ftrace.cpp;h=67ea3a02788416c670a6c1d3f12d591d402df84d;hb=98bac9636ee62a8863760a8b8381019a6a546173;hp=4de3f141cc87438bcf6f3d9b2ea1ef1b43822888;hpb=931f20b0dbd480153611493f51fee68f9d29be74;p=pulseview.git diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 4de3f14..67ea3a0 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -23,12 +23,16 @@ #include #include +#include +#include + #include "trace.h" #include "view.h" namespace pv { namespace view { +const QPen Trace::AxisPen(QColor(128, 128, 128, 64)); const int Trace::LabelHitPadding = 2; Trace::Trace(pv::SigSession &session, QString name) : @@ -68,8 +72,38 @@ void Trace::set_v_offset(int v_offset) _v_offset = v_offset; } -void Trace::paint_label(QPainter &p, int y, int right, bool hover) +void Trace::set_view(pv::view::View *view) +{ + assert(view); + _view = view; +} + +void Trace::paint_back(QPainter &p, int left, int right) +{ + (void)p; + (void)left; + (void)right; +} + +void Trace::paint_mid(QPainter &p, int left, int right) +{ + (void)p; + (void)left; + (void)right; +} + +void Trace::paint_fore(QPainter &p, int left, int right) +{ + (void)p; + (void)left; + (void)right; +} + +void Trace::paint_label(QPainter &p, int right, bool hover) { + assert(_view); + const int y = _v_offset - _view->v_offset(); + p.setBrush(_colour); if (!enabled()) @@ -78,7 +112,7 @@ void Trace::paint_label(QPainter &p, int y, int right, bool hover) const QColor colour = get_colour(); compute_text_size(p); - const QRectF label_rect = get_label_rect(y, right); + const QRectF label_rect = get_label_rect(right); // Paint the label const QPointF points[] = { @@ -116,16 +150,15 @@ void Trace::paint_label(QPainter &p, int y, int right, bool hover) p.drawPolygon(points, countof(points)); // Paint the text - p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white); + p.setPen(get_text_colour()); p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name); } -bool Trace::pt_in_label_rect(int y, int left, int right, - const QPoint &point) +bool Trace::pt_in_label_rect(int left, int right, const QPoint &point) { (void)left; - const QRectF label = get_label_rect(y, right); + const QRectF label = get_label_rect(right); return QRectF( QPointF(label.left() - LabelHitPadding, label.top() - LabelHitPadding), @@ -133,6 +166,39 @@ bool Trace::pt_in_label_rect(int y, int left, int right, ).contains(point); } +QMenu* Trace::create_context_menu(QWidget *parent) +{ + QMenu *const menu = SelectableItem::create_context_menu(parent); + + QAction *const set_name = new QAction(tr("Set &Name..."), this); + connect(set_name, SIGNAL(triggered()), + this, SLOT(on_action_set_name_triggered())); + menu->addAction(set_name); + + QAction *const set_colour = new QAction(tr("Set &Colour..."), this); + connect(set_colour, SIGNAL(triggered()), + this, SLOT(on_action_set_colour_triggered())); + menu->addAction(set_colour); + + return menu; +} + +int Trace::get_y() const +{ + return _v_offset - _view->v_offset(); +} + +QColor Trace::get_text_colour() const +{ + return (_colour.lightness() > 64) ? Qt::black : Qt::white; +} + +void Trace::paint_axis(QPainter &p, int y, int left, int right) +{ + p.setPen(AxisPen); + p.drawLine(QPointF(left, y + 0.5f), QPointF(right, y + 0.5f)); +} + void Trace::compute_text_size(QPainter &p) { _text_size = QSize( @@ -140,10 +206,13 @@ void Trace::compute_text_size(QPainter &p) p.boundingRect(QRectF(), 0, "Tg").height()); } -QRectF Trace::get_label_rect(int y, int right) +QRectF Trace::get_label_rect(int right) { using pv::view::View; + assert(_view); + const int y = _v_offset - _view->v_offset(); + const QSizeF label_size( _text_size.width() + View::LabelPadding.width() * 2, ceilf((_text_size.height() + View::LabelPadding.height() * 2) / 2) * 2); @@ -154,5 +223,27 @@ QRectF Trace::get_label_rect(int y, int right) label_size.width(), label_size.height()); } +void Trace::on_action_set_name_triggered() +{ + bool ok = false; + + const QString new_label = QInputDialog::getText(_context_parent, + tr("Set Name"), tr("Name"), QLineEdit::Normal, get_name(), + &ok); + + if (ok) + set_name(new_label); +} + +void Trace::on_action_set_colour_triggered() +{ + const QColor new_colour = QColorDialog::getColor( + get_colour(), _context_parent, tr("Set Colour")); + + if (new_colour.isValid()) + set_colour(new_colour); +} + + } // namespace view } // namespace pv