Remove Header::BaselineOffset and move arrows as needed instead
authorSoeren Apel <soeren@apelpie.net>
Thu, 1 Jun 2017 19:16:27 +0000 (21:16 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Fri, 2 Jun 2017 11:37:02 +0000 (13:37 +0200)
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.

pv/view/header.cpp
pv/view/header.hpp
pv/view/trace.cpp
pv/view/view.cpp

index e2ccfedc4e4d53cdb68d8897edaa1ec7f1622b24..7be804d0760a194dec0f63a476fc85c2f2c51588 100644 (file)
@@ -50,7 +50,6 @@ namespace views {
 namespace TraceView {
 
 const int Header::Padding = 12;
-const int Header::BaselineOffset = 5;
 
 static bool item_selected(shared_ptr<TraceTreeItem> 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<ViewItem> > Header::items()
 
 shared_ptr<ViewItem> 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<shared_ptr<TraceTreeItem>> items(
                view_.list_by_type<TraceTreeItem>());
        for (auto i = items.rbegin(); i != items.rend(); i++)
@@ -98,10 +97,7 @@ shared_ptr<ViewItem> 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<RowItem> > items(view_.list_by_type<RowItem>());
 
index c6f81ae5e5b96a4fd32bcc56a4835bd20e2bc2ff..6a4c9a39521863e9aac6e111d08b21b0ebcdbf5e 100644 (file)
@@ -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.
index 2154f8a7af1354216dce1b2874bc42e6064135c9..e5733372378f399dace15e5ba2124802f60fc5c0 100644 (file)
@@ -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()) {
index d9b02353adaf708f04ea47b2ad4b4cc1112d7bb0..6c3f896cfd9ff94f77cdc9c5a992af281514f969 100644 (file)
@@ -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