From: Soeren Apel Date: Thu, 1 Jun 2017 19:16:27 +0000 (+0200) Subject: Remove Header::BaselineOffset and move arrows as needed instead X-Git-Tag: pulseview-0.4.0~48 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c1a6513b912e90ebcca2dba4453aa03fbddcfb58;p=pulseview.git Remove Header::BaselineOffset and move arrows as needed instead The baseline offset was used to keep 5px of distance between the tip of the arrow and the scroll area. This way, the shadow that is drawn around the arrow when it's selected won't get cropped. However, we can do this differently: instead of always keeping the empty space around, we make the arrows align at the edge of the widget space as they should and when they're selected, we push them aside to the left so the shadow can still be painted without cropping. Logically, one would assume that the arrow's label also should be moving left but I decided against it because this way it looks as if the arrow didn't actually move, keeping all arrow labels lined up. --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index e2ccfedc..7be804d0 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -50,7 +50,6 @@ namespace views { namespace TraceView { const int Header::Padding = 12; -const int Header::BaselineOffset = 5; static bool item_selected(shared_ptr r) { @@ -70,7 +69,7 @@ QSize Header::sizeHint() const for (auto &i : items) if (i->enabled()) max_rect = max_rect.united(i->label_rect(QRect())); - return QSize(max_rect.width() + Padding + BaselineOffset, 0); + return QSize(max_rect.width() + Padding, 0); } QSize Header::extended_size_hint() const @@ -87,7 +86,7 @@ vector< shared_ptr > Header::items() shared_ptr Header::get_mouse_over_item(const QPoint &pt) { - const QRect r(0, 0, width() - BaselineOffset, height()); + const QRect r(0, 0, width(), height()); const vector> items( view_.list_by_type()); for (auto i = items.rbegin(); i != items.rend(); i++) @@ -98,10 +97,7 @@ shared_ptr Header::get_mouse_over_item(const QPoint &pt) void Header::paintEvent(QPaintEvent*) { - // The trace labels are not drawn with the arrows exactly on the - // left edge of the widget, because then the selection shadow - // would be clipped away. - const QRect rect(0, 0, width() - BaselineOffset, height()); + const QRect rect(0, 0, width(), height()); vector< shared_ptr > items(view_.list_by_type()); diff --git a/pv/view/header.hpp b/pv/view/header.hpp index c6f81ae5..6a4c9a39 100644 --- a/pv/view/header.hpp +++ b/pv/view/header.hpp @@ -56,12 +56,6 @@ public: */ QSize extended_size_hint() const; - /** - * The horizontal offset, relative to the left edge of the widget, - * where the arrows of the trace labels end. - */ - static const int BaselineOffset; - private: /** * Gets the row items. diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 2154f8a7..e5733372 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -75,21 +75,24 @@ void Trace::paint_label(QPainter &p, const QRect &rect, bool hover) const QRectF r = label_rect(rect); + // When selected, move the arrow to the left so that the border can show + const QPointF offs = (selected()) ? QPointF(-2, 0) : QPointF(0, 0); + // Paint the label const float label_arrow_length = r.height() / 2; - const QPointF points[] = { - r.topLeft(), - QPointF(r.right() - label_arrow_length, r.top()), - QPointF(r.right(), y), - QPointF(r.right() - label_arrow_length, r.bottom()), - r.bottomLeft() + QPointF points[] = { + offs + r.topLeft(), + offs + QPointF(r.right() - label_arrow_length, r.top()), + offs + QPointF(r.right(), y), + offs + QPointF(r.right() - label_arrow_length, r.bottom()), + offs + r.bottomLeft() }; - const QPointF highlight_points[] = { - QPointF(r.left() + 1, r.top() + 1), - QPointF(r.right() - label_arrow_length, r.top() + 1), - QPointF(r.right() - 1, y), - QPointF(r.right() - label_arrow_length, r.bottom() - 1), - QPointF(r.left() + 1, r.bottom() - 1) + QPointF highlight_points[] = { + offs + QPointF(r.left() + 1, r.top() + 1), + offs + QPointF(r.right() - label_arrow_length, r.top() + 1), + offs + QPointF(r.right() - 1, y), + offs + QPointF(r.right() - label_arrow_length, r.bottom() - 1), + offs + QPointF(r.left() + 1, r.bottom() - 1) }; if (selected()) { diff --git a/pv/view/view.cpp b/pv/view/view.cpp index d9b02353..6c3f896c 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -155,7 +155,7 @@ View::View(Session &session, bool is_main_view, QWidget *parent) : ruler_ = new Ruler(*this); header_ = new Header(*this); - header_->setMinimumWidth(15); // So that the arrow tips show at least + header_->setMinimumWidth(10); // So that the arrow tips show at least // We put the header into a simple layout so that we can add the top margin, // allowing us to make it line up with the bottom of the ruler