]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | */ | |
20 | ||
21 | #include <QMenu> | |
22 | #include <QMouseEvent> | |
23 | ||
24 | #include "view.hpp" | |
25 | ||
26 | #include "marginwidget.hpp" | |
27 | ||
28 | #include <pv/widgets/popup.hpp> | |
29 | ||
30 | using std::shared_ptr; | |
31 | ||
32 | namespace pv { | |
33 | namespace views { | |
34 | namespace TraceView { | |
35 | ||
36 | MarginWidget::MarginWidget(View &parent) : | |
37 | ViewWidget(parent) | |
38 | { | |
39 | setAttribute(Qt::WA_NoSystemBackground, true); | |
40 | } | |
41 | ||
42 | void MarginWidget::item_clicked(const shared_ptr<ViewItem> &item) | |
43 | { | |
44 | if (item && item->enabled()) | |
45 | show_popup(item); | |
46 | } | |
47 | ||
48 | void MarginWidget::show_popup(const shared_ptr<ViewItem> &item) | |
49 | { | |
50 | pv::widgets::Popup *const p = item->create_popup(this); | |
51 | if (p) | |
52 | p->show(); | |
53 | } | |
54 | ||
55 | void MarginWidget::contextMenuEvent(QContextMenuEvent *event) | |
56 | { | |
57 | const shared_ptr<ViewItem> r = get_mouse_over_item(mouse_point_); | |
58 | if (!r) | |
59 | return; | |
60 | ||
61 | QMenu *menu = r->create_context_menu(this); | |
62 | if (menu) | |
63 | menu->exec(event->globalPos()); | |
64 | } | |
65 | ||
66 | void MarginWidget::keyPressEvent(QKeyEvent *event) | |
67 | { | |
68 | assert(event); | |
69 | ||
70 | if (event->key() == Qt::Key_Delete) { | |
71 | const auto items = this->items(); | |
72 | for (auto &i : items) | |
73 | if (i->selected()) | |
74 | i->delete_pressed(); | |
75 | } | |
76 | } | |
77 | ||
78 | } // namespace TraceView | |
79 | } // namespace views | |
80 | } // namespace pv |