]> sigrok.org Git - pulseview.git/blame - pv/view/marginwidget.cpp
MainWindow: Fix session error slot declaration
[pulseview.git] / pv / view / marginwidget.cpp
CommitLineData
c23b29d6
JH
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
2155b66b
JH
21#include <QMenu>
22#include <QMouseEvent>
23
2acdb232 24#include "view.hpp"
c23b29d6 25
2acdb232 26#include "marginwidget.hpp"
c23b29d6 27
786b7678
JH
28#include <pv/widgets/popup.hpp>
29
30using std::shared_ptr;
31
c23b29d6 32namespace pv {
f4e57597
SA
33namespace views {
34namespace TraceView {
c23b29d6
JH
35
36MarginWidget::MarginWidget(View &parent) :
e9e4e5e7 37 ViewWidget(parent)
c23b29d6 38{
e02e05c6 39 setAttribute(Qt::WA_NoSystemBackground, true);
e9e4e5e7
JH
40}
41
42void MarginWidget::item_clicked(const shared_ptr<ViewItem> &item)
43{
44 if (item && item->enabled())
45 show_popup(item);
c23b29d6
JH
46}
47
786b7678
JH
48void 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
2155b66b
JH
55void 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
d9ea9628 66void MarginWidget::keyPressEvent(QKeyEvent *event)
bb4a0e8e 67{
d9ea9628 68 assert(event);
bb4a0e8e 69
d9ea9628 70 if (event->key() == Qt::Key_Delete) {
bb4a0e8e
JH
71 const auto items = this->items();
72 for (auto &i : items)
73 if (i->selected())
74 i->delete_pressed();
75 }
76}
77
f4e57597
SA
78} // namespace TraceView
79} // namespace views
c23b29d6 80} // namespace pv