X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Ftrace.cpp;h=87d3dc1dc095fa7ebd7b1dd2b7dba0bf5c255c8e;hp=2e15ca958a1da81af2ebba507328da0b9cb801b6;hb=3b353d67bba8fc2076d03e93fed6483572600fa9;hpb=cbf0f87e496c9d9157591c94dc445aaa960fe79d diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 2e15ca95..87d3dc1d 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -38,11 +38,16 @@ namespace pv { namespace view { -const QPen Trace::AxisPen(QColor(128, 128, 128, 64)); +const QPen Trace::AxisPen(QColor(0, 0, 0, 30*256/100)); const int Trace::LabelHitPadding = 2; +const int Trace::ColourBGAlpha = 8*256/100; +const QColor Trace::BrightGrayBGColour = QColor(0, 0, 0, 10*255/100); +const QColor Trace::DarkGrayBGColour = QColor(0, 0, 0, 15*255/100); + Trace::Trace(QString name) : name_(name), + coloured_bg_(true), // Default setting is set in MainWindow::setup_ui() popup_(nullptr), popup_form_(nullptr) { @@ -66,6 +71,14 @@ QColor Trace::colour() const void Trace::set_colour(QColor colour) { colour_ = colour; + + bgcolour_ = colour; + bgcolour_.setAlpha(ColourBGAlpha); +} + +void Trace::set_coloured_bg(bool state) +{ + coloured_bg_ = state; } void Trace::paint_label(QPainter &p, const QRect &rect, bool hover) @@ -163,17 +176,33 @@ QRectF Trace::label_rect(const QRectF &rect) const label_size.height()); } -QRectF Trace::hit_box_rect(const ViewItemPaintParams &pp) const +void Trace::paint_back(QPainter &p, const ViewItemPaintParams &pp) { - const float h = QFontMetrics(QApplication::font()).height(); - return QRectF(pp.left(), get_visual_y() - h / 2.0f, - pp.width(), h); + if (coloured_bg_) + p.setBrush(bgcolour_); + else + p.setBrush(bgcolour_state_ ? BrightGrayBGColour : DarkGrayBGColour); + + p.setPen(QPen(Qt::NoPen)); + + const std::pair extents = v_extents(); + + const int x = 0; + const int y = get_visual_y() + extents.first; + const int w = pp.right() - pp.left(); + const int h = extents.second - extents.first; + + p.drawRect(x, y, w, h); } void Trace::paint_axis(QPainter &p, const ViewItemPaintParams &pp, int y) { + p.setRenderHint(QPainter::Antialiasing, false); + p.setPen(AxisPen); - p.drawLine(QPointF(pp.left(), y + 0.5f), QPointF(pp.right(), y + 0.5f)); + p.drawLine(QPointF(pp.left(), y), QPointF(pp.right(), y)); + + p.setRenderHint(QPainter::Antialiasing, true); } void Trace::add_colour_option(QWidget *parent, QFormLayout *form) @@ -195,10 +224,14 @@ void Trace::create_popup_form() // Clear the layout // Transfer the layout and the child widgets to a temporary widget - // which then goes out of scope destroying the layout and all the child - // widgets. - if (popup_form_) - QWidget().setLayout(popup_form_); + // which we delete after the event was handled. This way, the layout + // and all widgets contained therein are deleted after the event was + // handled, leaving the parent popup_ time to handle the change. + if (popup_form_) { + QWidget *suicidal = new QWidget(); + suicidal->setLayout(popup_form_); + suicidal->deleteLater(); + } // Repopulate the popup popup_form_ = new QFormLayout(popup_); @@ -236,7 +269,7 @@ void Trace::on_colour_changed(const QColor &colour) set_colour(colour); if (owner_) - owner_->row_item_appearance_changed(true, false); + owner_->row_item_appearance_changed(true, true); } } // namespace view