2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <QApplication>
23 #include <QMouseEvent>
27 #include "marginwidget.hpp"
29 #include <pv/widgets/popup.hpp>
31 using std::shared_ptr;
36 MarginWidget::MarginWidget(View &parent) :
41 setAttribute(Qt::WA_NoSystemBackground, true);
42 setFocusPolicy(Qt::ClickFocus);
43 setMouseTracking(true);
46 void MarginWidget::show_popup(const shared_ptr<ViewItem> &item)
48 pv::widgets::Popup *const p = item->create_popup(this);
53 void MarginWidget::mouse_left_press_event(QMouseEvent *event)
57 const bool ctrl_pressed =
58 QApplication::keyboardModifiers() & Qt::ControlModifier;
60 // Clear selection if control is not pressed and this item is unselected
61 if ((!mouse_down_item_ || !mouse_down_item_->selected()) &&
65 // Set the signal selection state if the item has been clicked
66 if (mouse_down_item_) {
68 mouse_down_item_->select(!mouse_down_item_->selected());
70 mouse_down_item_->select(true);
73 // Save the offsets of any signals which will be dragged
74 const auto items = this->items();
83 void MarginWidget::mouse_left_release_event(QMouseEvent *event)
87 auto items = this->items();
88 const bool ctrl_pressed =
89 QApplication::keyboardModifiers() & Qt::ControlModifier;
91 // Unselect everything if control is not pressed
92 const shared_ptr<ViewItem> mouse_over =
93 get_mouse_over_item(event->pos());
99 view_.restack_all_row_items();
103 for (shared_ptr<ViewItem> i : items)
104 if (mouse_down_item_ != i)
107 if (mouse_down_item_)
108 show_popup(mouse_down_item_);
115 void MarginWidget::mousePressEvent(QMouseEvent *event)
119 mouse_down_point_ = event->pos();
120 mouse_down_item_ = get_mouse_over_item(event->pos());
122 if (event->button() & Qt::LeftButton)
123 mouse_left_press_event(event);
126 void MarginWidget::mouseReleaseEvent(QMouseEvent *event)
129 if (event->button() & Qt::LeftButton)
130 mouse_left_release_event(event);
132 mouse_down_item_ = nullptr;
135 void MarginWidget::leaveEvent(QEvent*)
137 mouse_point_ = QPoint(-1, -1);
141 void MarginWidget::contextMenuEvent(QContextMenuEvent *event)
143 const shared_ptr<ViewItem> r = get_mouse_over_item(mouse_point_);
147 QMenu *menu = r->create_context_menu(this);
149 menu->exec(event->globalPos());
152 void MarginWidget::keyPressEvent(QKeyEvent *e)
156 if (e->key() == Qt::Key_Delete)
158 const auto items = this->items();
159 for (auto &i : items)
165 void MarginWidget::clear_selection()
167 const auto items = this->items();
168 for (auto &i : items)