]> sigrok.org Git - pulseview.git/blobdiff - pv/view/marginwidget.cpp
Change namespace for the trace view and implement ViewBase
[pulseview.git] / pv / view / marginwidget.cpp
index e20e7b9f00afe664e72439969b73fe5894b6eca7..4c3728710551bfceef85fad0234bffc51f44a119 100644 (file)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <QApplication>
 #include <QMenu>
 #include <QMouseEvent>
 
 using std::shared_ptr;
 
 namespace pv {
-namespace view {
+namespace views {
+namespace TraceView {
 
 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)
@@ -50,53 +52,6 @@ void MarginWidget::show_popup(const shared_ptr<ViewItem> &item)
                p->show();
 }
 
-void MarginWidget::mouse_left_press_event(QMouseEvent *event)
-{
-       (void)event;
-
-       const bool ctrl_pressed =
-               QApplication::keyboardModifiers() & Qt::ControlModifier;
-
-       // Clear selection if control is not pressed and this item is unselected
-       if ((!mouse_down_item_ || !mouse_down_item_->selected()) &&
-               !ctrl_pressed)
-               clear_selection();
-
-       // Set the signal selection state if the item has been clicked
-       if (mouse_down_item_) {
-               if (ctrl_pressed)
-                       mouse_down_item_->select(!mouse_down_item_->selected());
-               else
-                       mouse_down_item_->select(true);
-       }
-
-       // Save the offsets of any signals which will be dragged
-       const auto items = this->items();
-       for (auto &i : items)
-               if (i->selected())
-                       i->drag();
-
-       selection_changed();
-       update();
-}
-
-void MarginWidget::mousePressEvent(QMouseEvent *event)
-{
-       assert(event);
-
-       mouse_down_point_ = event->pos();
-       mouse_down_item_ = get_mouse_over_item(event->pos());
-
-       if (event->button() & Qt::LeftButton)
-               mouse_left_press_event(event);
-}
-
-void MarginWidget::leaveEvent(QEvent*)
-{
-       mouse_point_ = QPoint(-1, -1);
-       update();
-}
-
 void MarginWidget::contextMenuEvent(QContextMenuEvent *event)
 {
        const shared_ptr<ViewItem> r = get_mouse_over_item(mouse_point_);
@@ -108,13 +63,18 @@ void MarginWidget::contextMenuEvent(QContextMenuEvent *event)
                menu->exec(event->globalPos());
 }
 
-void MarginWidget::clear_selection()
+void MarginWidget::keyPressEvent(QKeyEvent *event)
 {
-       const auto items = this->items();
-       for (auto &i : items)
-               i->select(false);
-       update();
+       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
+} // namespace TraceView
+} // namespace views
 } // namespace pv