X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fheader.cpp;h=7be804d0760a194dec0f63a476fc85c2f2c51588;hp=58c21e596c7ab9ace1beb392a5510b270609dddf;hb=c1a6513b912e90ebcca2dba4453aa03fbddcfb58;hpb=cc88566ce77bed57358a82dec5da648feb66d10b diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 58c21e59..7be804d0 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ #include "header.hpp" @@ -24,8 +23,8 @@ #include "signal.hpp" #include "tracegroup.hpp" -#include #include +#include #include @@ -39,20 +38,18 @@ #include using boost::make_filter_iterator; + +using std::count_if; using std::dynamic_pointer_cast; -using std::max; -using std::make_pair; -using std::min; -using std::pair; using std::shared_ptr; using std::stable_sort; using std::vector; namespace pv { -namespace view { +namespace views { +namespace TraceView { const int Header::Padding = 12; -const int Header::BaselineOffset = 5; static bool item_selected(shared_ptr r) { @@ -72,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 @@ -89,34 +86,29 @@ 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) - if (i->enabled() && i->label_rect(r).contains(pt)) - return i; + for (auto i = items.rbegin(); i != items.rend(); i++) + if ((*i)->enabled() && (*i)->label_rect(r).contains(pt)) + return *i; return shared_ptr(); } 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()); + vector< shared_ptr > items(view_.list_by_type()); stable_sort(items.begin(), items.end(), - [](const shared_ptr &a, const shared_ptr &b) { - return a->visual_v_offset() < b->visual_v_offset(); }); + [](const shared_ptr &a, const shared_ptr &b) { + return a->point(QRect()).y() < b->point(QRect()).y(); }); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); - for (const shared_ptr r : items) - { + for (const shared_ptr r : items) { assert(r); const bool highlight = !item_dragging_ && @@ -139,8 +131,7 @@ void Header::contextMenuEvent(QContextMenuEvent *event) const vector< shared_ptr > items( view_.list_by_type()); - if (std::count_if(items.begin(), items.end(), item_selected) > 1) - { + if (count_if(items.begin(), items.end(), item_selected) > 1) { menu->addSeparator(); QAction *const group = new QAction(tr("Group"), this); @@ -154,15 +145,15 @@ void Header::contextMenuEvent(QContextMenuEvent *event) menu->exec(event->globalPos()); } -void Header::keyPressEvent(QKeyEvent *e) +void Header::keyPressEvent(QKeyEvent *event) { - assert(e); + assert(event); - MarginWidget::keyPressEvent(e); + MarginWidget::keyPressEvent(event); - if (e->key() == Qt::Key_G && e->modifiers() == Qt::ControlModifier) + if (event->key() == Qt::Key_G && event->modifiers() == Qt::ControlModifier) on_group(); - else if (e->key() == Qt::Key_U && e->modifiers() == Qt::ControlModifier) + else if (event->key() == Qt::Key_U && event->modifiers() == Qt::ControlModifier) on_ungroup(); } @@ -179,7 +170,7 @@ void Header::on_group() shared_ptr group(new TraceGroup()); shared_ptr mouse_down_item( - std::dynamic_pointer_cast(mouse_down_item_)); + dynamic_pointer_cast(mouse_down_item_)); shared_ptr focus_item( mouse_down_item ? mouse_down_item : selected_items.front()); @@ -219,5 +210,6 @@ void Header::on_ungroup() } while (restart); } -} // namespace view +} // namespace TraceView +} // namespace views } // namespace pv