From: Joel Holdsworth Date: Sat, 20 Dec 2014 08:50:26 +0000 (+0000) Subject: Flag: Added delete key support X-Git-Tag: pulseview-0.3.0~344 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=dbfae3f1b55b984c7ee7e619a8da53b77db98c90 Flag: Added delete key support --- diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index fbc6e2e7..efc9205e 100644 --- a/pv/view/cursorheader.cpp +++ b/pv/view/cursorheader.cpp @@ -49,7 +49,6 @@ CursorHeader::CursorHeader(View &parent) : MarginWidget(parent), textHeight_(calculateTextHeight()) { - setMouseTracking(true); } QSize CursorHeader::sizeHint() const @@ -162,5 +161,18 @@ void CursorHeader::mouseDoubleClickEvent(QMouseEvent *e) view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale()); } +void CursorHeader::keyPressEvent(QKeyEvent *e) +{ + assert(e); + + if (e->key() == Qt::Key_Delete) + { + const vector< shared_ptr > items(view_.time_items()); + for (auto &i : items) + if (i->selected()) + i->delete_pressed(); + } +} + } // namespace view } // namespace pv diff --git a/pv/view/cursorheader.hpp b/pv/view/cursorheader.hpp index 8db64086..ff732856 100644 --- a/pv/view/cursorheader.hpp +++ b/pv/view/cursorheader.hpp @@ -62,6 +62,9 @@ private: void mouseDoubleClickEvent(QMouseEvent *e); + void keyPressEvent(QKeyEvent *e); + +private: int calculateTextHeight(); std::shared_ptr mouse_down_item_; diff --git a/pv/view/flag.cpp b/pv/view/flag.cpp index 53b0feef..2ee8ced4 100644 --- a/pv/view/flag.cpp +++ b/pv/view/flag.cpp @@ -43,7 +43,8 @@ Flag::Flag(View &view, double time, const QString &text) : } Flag::Flag(const Flag &flag) : - TimeMarker(flag.view_, FillColour, flag.time_) + TimeMarker(flag.view_, FillColour, flag.time_), + std::enable_shared_from_this(flag) { } @@ -73,6 +74,11 @@ pv::widgets::Popup* Flag::create_popup(QWidget *parent) return popup; } +void Flag::delete_pressed() +{ + view_.remove_flag(shared_ptr(shared_from_this())); +} + void Flag::on_text_changed(const QString &text) { text_ = text; diff --git a/pv/view/flag.hpp b/pv/view/flag.hpp index 659d5cc1..fdebe1c0 100644 --- a/pv/view/flag.hpp +++ b/pv/view/flag.hpp @@ -21,12 +21,15 @@ #ifndef PULSEVIEW_PV_VIEW_FLAG_H #define PULSEVIEW_PV_VIEW_FLAG_H +#include + #include "timemarker.hpp" namespace pv { namespace view { -class Flag : public TimeMarker +class Flag : public TimeMarker, + public std::enable_shared_from_this { Q_OBJECT @@ -59,6 +62,8 @@ public: pv::widgets::Popup* create_popup(QWidget *parent); + void delete_pressed(); + private Q_SLOTS: void on_text_changed(const QString &text); diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 780b1e3d..4b02c194 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -62,9 +62,6 @@ static bool item_selected(shared_ptr r) Header::Header(View &parent) : MarginWidget(parent) { - setFocusPolicy(Qt::ClickFocus); - setMouseTracking(true); - connect(&view_, SIGNAL(signals_moved()), this, SLOT(on_signals_moved())); } diff --git a/pv/view/marginwidget.cpp b/pv/view/marginwidget.cpp index e44233c8..f8302f64 100644 --- a/pv/view/marginwidget.cpp +++ b/pv/view/marginwidget.cpp @@ -31,6 +31,8 @@ MarginWidget::MarginWidget(View &parent) : dragging_(false) { setAttribute(Qt::WA_NoSystemBackground, true); + setFocusPolicy(Qt::ClickFocus); + setMouseTracking(true); } void MarginWidget::clear_selection() diff --git a/pv/view/timeitem.hpp b/pv/view/timeitem.hpp index 80fecb5d..83742442 100644 --- a/pv/view/timeitem.hpp +++ b/pv/view/timeitem.hpp @@ -29,6 +29,7 @@ namespace view { class View; class TimeItem : public ViewItem + { Q_OBJECT