X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fmarginwidget.cpp;h=7e4fcdfa76aed109e0e8bfb6cb2032f6690bbdb6;hp=5a81c45933450b40e5aee63d36116b75eeba6b8b;hb=d9ea96280ab1128427143660ae375c30b19aa0cb;hpb=bb4a0e8e0b337988264e43a368b6ce5950d2d6cd diff --git a/pv/view/marginwidget.cpp b/pv/view/marginwidget.cpp index 5a81c459..7e4fcdfa 100644 --- a/pv/view/marginwidget.cpp +++ b/pv/view/marginwidget.cpp @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include #include @@ -34,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 &item) +{ + if (item && item->enabled()) + show_popup(item); } void MarginWidget::show_popup(const shared_ptr &item) @@ -50,53 +51,6 @@ void MarginWidget::show_popup(const shared_ptr &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 r = get_mouse_over_item(mouse_point_); @@ -108,12 +62,11 @@ void MarginWidget::contextMenuEvent(QContextMenuEvent *event) menu->exec(event->globalPos()); } -void MarginWidget::keyPressEvent(QKeyEvent *e) +void MarginWidget::keyPressEvent(QKeyEvent *event) { - assert(e); + assert(event); - if (e->key() == Qt::Key_Delete) - { + if (event->key() == Qt::Key_Delete) { const auto items = this->items(); for (auto &i : items) if (i->selected()) @@ -121,13 +74,5 @@ void MarginWidget::keyPressEvent(QKeyEvent *e) } } -void MarginWidget::clear_selection() -{ - const auto items = this->items(); - for (auto &i : items) - i->select(false); - update(); -} - } // namespace view } // namespace pv