Allow for a context menu in the view area
authorSoeren Apel <soeren@apelpie.net>
Thu, 2 Aug 2018 06:56:51 +0000 (08:56 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Tue, 21 Aug 2018 10:02:38 +0000 (12:02 +0200)
pv/views/trace/trace.cpp
pv/views/trace/trace.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp
pv/views/trace/viewitem.cpp
pv/views/trace/viewitem.hpp
pv/views/trace/viewport.hpp

index 7d8501122753aabe9f4d739d2dbea82d211fab5b..3b79dcd98aea33db43ca32fbe9f37415048dc2c6 100644 (file)
@@ -187,6 +187,14 @@ QRectF Trace::label_rect(const QRectF &rect) const
                label_size.height());
 }
 
                label_size.height());
 }
 
+QRectF Trace::hit_box_rect(const ViewItemPaintParams &pp) const
+{
+       pair<int, int> extents = v_extents();
+       const int top = pp.top() + get_visual_y() + extents.first;
+       const int height = extents.second - extents.first;
+       return QRectF(pp.left(), top, pp.width(), height);
+}
+
 void Trace::set_current_segment(const int segment)
 {
        current_segment_ = segment;
 void Trace::set_current_segment(const int segment)
 {
        current_segment_ = segment;
index d6d53045e4bbf69ce68aff934a94195280a40d38..bc97736c03de58f1ccc4d9d2e09571c110c6d909 100644 (file)
@@ -128,6 +128,14 @@ public:
         */
        QRectF label_rect(const QRectF &rect) const;
 
         */
        QRectF label_rect(const QRectF &rect) const;
 
+       /**
+        * Computes the outline rectangle of the viewport hit-box.
+        * @param rect the rectangle of the viewport area.
+        * @return Returns the rectangle of the hit-box.
+        * @remarks The default implementation returns an empty hit-box.
+        */
+       virtual QRectF hit_box_rect(const ViewItemPaintParams &pp) const;
+
        void set_current_segment(const int segment);
 
        int get_current_segment() const;
        void set_current_segment(const int segment);
 
        int get_current_segment() const;
index 024e3bf48d665b0043252551c72ef2202da80de5..99e75bfdc9ec72de6281d86b3d922e626a5911a5 100644 (file)
@@ -38,6 +38,7 @@
 #include <QApplication>
 #include <QEvent>
 #include <QFontMetrics>
 #include <QApplication>
 #include <QEvent>
 #include <QFontMetrics>
+#include <QMenu>
 #include <QMouseEvent>
 #include <QScrollBar>
 #include <QVBoxLayout>
 #include <QMouseEvent>
 #include <QScrollBar>
 #include <QVBoxLayout>
@@ -1251,6 +1252,17 @@ bool View::eventFilter(QObject *object, QEvent *event)
        return QObject::eventFilter(object, event);
 }
 
        return QObject::eventFilter(object, event);
 }
 
+void View::contextMenuEvent(QContextMenuEvent *event)
+{
+       const shared_ptr<ViewItem> r = viewport_->get_mouse_over_item(event->pos());
+       if (!r)
+               return;
+
+       QMenu *menu = r->create_view_context_menu(this);
+       if (menu)
+               menu->exec(event->globalPos());
+}
+
 void View::resizeEvent(QResizeEvent* event)
 {
        // Only adjust the top margin if we shrunk vertically
 void View::resizeEvent(QResizeEvent* event)
 {
        // Only adjust the top margin if we shrunk vertically
index 4f364404ce01acf2c9f9b4ee18d8cfb2dc517843..1cff6ab7bbf245f52a7508c20b52b446e26d15bc 100644 (file)
@@ -394,6 +394,8 @@ private:
 
        bool eventFilter(QObject *object, QEvent *event);
 
 
        bool eventFilter(QObject *object, QEvent *event);
 
+       virtual void contextMenuEvent(QContextMenuEvent *event);
+
        void resizeEvent(QResizeEvent *event);
 
        void update_hover_point();
        void resizeEvent(QResizeEvent *event);
 
        void update_hover_point();
index 2141687c92b12fc546bbe87346681a65655dc4d3..7c1fae736699e2215aefb71e7aaec1f0a714fe00 100644 (file)
@@ -88,6 +88,12 @@ QMenu* ViewItem::create_context_menu(QWidget *parent)
        return new QMenu(parent);
 }
 
        return new QMenu(parent);
 }
 
+QMenu* ViewItem::create_view_context_menu(QWidget *parent)
+{
+       (void)parent;
+       return nullptr;
+}
+
 widgets::Popup* ViewItem::create_popup(QWidget *parent)
 {
        (void)parent;
 widgets::Popup* ViewItem::create_popup(QWidget *parent)
 {
        (void)parent;
index f3e0f9b67f5470b6942ae52d10351a2c58ea5db2..91242f57478e3bb9223bb8f01abf14118853c21a 100644 (file)
@@ -157,6 +157,8 @@ public:
 public:
        virtual QMenu* create_context_menu(QWidget *parent);
 
 public:
        virtual QMenu* create_context_menu(QWidget *parent);
 
+       virtual QMenu* create_view_context_menu(QWidget *parent);
+
        virtual pv::widgets::Popup* create_popup(QWidget *parent);
 
        virtual void delete_pressed();
        virtual pv::widgets::Popup* create_popup(QWidget *parent);
 
        virtual void delete_pressed();
index ab67f69f3ee2d618895b6d5595a7251f97ef538c..a49084b43ebe901f6e9cd7bb6ab2ad199e41e580 100644 (file)
@@ -48,14 +48,6 @@ class Viewport : public ViewWidget
 public:
        explicit Viewport(View &parent);
 
 public:
        explicit Viewport(View &parent);
 
-private:
-       /**
-        * Indicates when a view item is being hovered over.
-        * @param item The item that is being hovered over, or @c nullptr
-        * if no view item is being hovered over.
-        */
-       void item_hover(const shared_ptr<ViewItem> &item);
-
        /**
         * Gets the first view item which has a hit-box that contains @c pt .
         * @param pt the point to search with.
        /**
         * Gets the first view item which has a hit-box that contains @c pt .
         * @param pt the point to search with.
@@ -64,6 +56,14 @@ private:
         */
        shared_ptr<ViewItem> get_mouse_over_item(const QPoint &pt);
 
         */
        shared_ptr<ViewItem> get_mouse_over_item(const QPoint &pt);
 
+private:
+       /**
+        * Indicates when a view item is being hovered over.
+        * @param item The item that is being hovered over, or @c nullptr
+        * if no view item is being hovered over.
+        */
+       void item_hover(const shared_ptr<ViewItem> &item);
+
        /**
         * Sets this item into the dragged state.
         */
        /**
         * Sets this item into the dragged state.
         */