]>
Commit | Line | Data |
---|---|---|
8914fe79 JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2014 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 | |
efdec55a | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
8914fe79 JH |
18 | */ |
19 | ||
20 | #include "timemarker.hpp" | |
21 | #include "view.hpp" | |
22 | ||
23 | #include <QColor> | |
24 | #include <QFormLayout> | |
25 | #include <QLineEdit> | |
97430d77 | 26 | #include <QMenu> |
8914fe79 | 27 | |
fe3a1c21 | 28 | #include <libsigrokcxx/libsigrokcxx.hpp> |
8914fe79 JH |
29 | |
30 | #include <pv/widgets/popup.hpp> | |
31 | ||
6f925ba9 | 32 | using std::enable_shared_from_this; |
8914fe79 JH |
33 | using std::shared_ptr; |
34 | ||
35 | namespace pv { | |
f4e57597 | 36 | namespace views { |
1573bf16 | 37 | namespace trace { |
8914fe79 | 38 | |
3782d860 | 39 | const QColor Flag::FillColor(0x73, 0xD2, 0x16); |
8914fe79 | 40 | |
60d9b99a | 41 | Flag::Flag(View &view, const pv::util::Timestamp& time, const QString &text) : |
3782d860 | 42 | TimeMarker(view, FillColor, time), |
8914fe79 JH |
43 | text_(text) |
44 | { | |
45 | } | |
46 | ||
47 | Flag::Flag(const Flag &flag) : | |
3782d860 | 48 | TimeMarker(flag.view_, FillColor, flag.time_), |
6f925ba9 | 49 | enable_shared_from_this<Flag>(flag) |
8914fe79 JH |
50 | { |
51 | } | |
52 | ||
53 | bool Flag::enabled() const | |
54 | { | |
55 | return true; | |
56 | } | |
57 | ||
58 | QString Flag::get_text() const | |
59 | { | |
60 | return text_; | |
61 | } | |
62 | ||
63 | pv::widgets::Popup* Flag::create_popup(QWidget *parent) | |
64 | { | |
786b7678 JH |
65 | using pv::widgets::Popup; |
66 | ||
67 | Popup *const popup = TimeMarker::create_popup(parent); | |
68 | popup->set_position(parent->mapToGlobal( | |
3782d860 | 69 | drag_point(parent->rect())), Popup::Bottom); |
786b7678 | 70 | |
8914fe79 JH |
71 | QFormLayout *const form = (QFormLayout*)popup->layout(); |
72 | ||
73 | QLineEdit *const text_edit = new QLineEdit(popup); | |
74 | text_edit->setText(text_); | |
75 | ||
76 | connect(text_edit, SIGNAL(textChanged(const QString&)), | |
77 | this, SLOT(on_text_changed(const QString&))); | |
78 | ||
79 | form->insertRow(0, tr("Text"), text_edit); | |
80 | ||
81 | return popup; | |
82 | } | |
83 | ||
3782d860 | 84 | QMenu* Flag::create_header_context_menu(QWidget *parent) |
97430d77 JH |
85 | { |
86 | QMenu *const menu = new QMenu(parent); | |
87 | ||
88 | QAction *const del = new QAction(tr("Delete"), this); | |
89 | del->setShortcuts(QKeySequence::Delete); | |
90 | connect(del, SIGNAL(triggered()), this, SLOT(on_delete())); | |
91 | menu->addAction(del); | |
92 | ||
93 | return menu; | |
94 | } | |
95 | ||
dbfae3f1 | 96 | void Flag::delete_pressed() |
97430d77 JH |
97 | { |
98 | on_delete(); | |
99 | } | |
100 | ||
101 | void Flag::on_delete() | |
dbfae3f1 JH |
102 | { |
103 | view_.remove_flag(shared_ptr<Flag>(shared_from_this())); | |
104 | } | |
105 | ||
8914fe79 JH |
106 | void Flag::on_text_changed(const QString &text) |
107 | { | |
108 | text_ = text; | |
109 | view_.time_item_appearance_changed(true, false); | |
110 | } | |
111 | ||
1573bf16 | 112 | } // namespace trace |
f4e57597 | 113 | } // namespace views |
8914fe79 | 114 | } // namespace pv |