]> sigrok.org Git - pulseview.git/blobdiff - pv/view/marginwidget.cpp
Standardize on 'event' as name for all Qt events.
[pulseview.git] / pv / view / marginwidget.cpp
index b4b12140276c0b4faf11f9dab36a4d6a6ed7c117..7e4fcdfa76aed109e0e8bfb6cb2032f6690bbdb6 100644 (file)
@@ -18,6 +18,9 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <QMenu>
+#include <QMouseEvent>
+
 #include "view.hpp"
 
 #include "marginwidget.hpp"
@@ -30,13 +33,15 @@ namespace pv {
 namespace view {
 
 MarginWidget::MarginWidget(View &parent) :
-       QWidget(&parent),
-       view_(parent),
-       dragging_(false)
+       ViewWidget(parent)
 {
        setAttribute(Qt::WA_NoSystemBackground, true);
-       setFocusPolicy(Qt::ClickFocus);
-       setMouseTracking(true);
+}
+
+void MarginWidget::item_clicked(const shared_ptr<ViewItem> &item)
+{
+       if (item && item->enabled())
+               show_popup(item);
 }
 
 void MarginWidget::show_popup(const shared_ptr<ViewItem> &item)
@@ -46,14 +51,27 @@ void MarginWidget::show_popup(const shared_ptr<ViewItem> &item)
                p->show();
 }
 
-void MarginWidget::leaveEvent(QEvent*)
+void MarginWidget::contextMenuEvent(QContextMenuEvent *event)
 {
-       mouse_point_ = QPoint(-1, -1);
-       update();
+       const shared_ptr<ViewItem> r = get_mouse_over_item(mouse_point_);
+       if (!r)
+               return;
+
+       QMenu *menu = r->create_context_menu(this);
+       if (menu)
+               menu->exec(event->globalPos());
 }
 
-void MarginWidget::clear_selection()
+void MarginWidget::keyPressEvent(QKeyEvent *event)
 {
+       assert(event);
+
+       if (event->key() == Qt::Key_Delete) {
+               const auto items = this->items();
+               for (auto &i : items)
+                       if (i->selected())
+                               i->delete_pressed();
+       }
 }
 
 } // namespace view