]> sigrok.org Git - pulseview.git/blame_incremental - pv/views/trace/flag.cpp
Disable antialiasing on high-DPI displays
[pulseview.git] / pv / views / trace / flag.cpp
... / ...
CommitLineData
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
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "timemarker.hpp"
21#include "view.hpp"
22
23#include <QColor>
24#include <QFormLayout>
25#include <QLineEdit>
26#include <QMenu>
27
28#include <libsigrokcxx/libsigrokcxx.hpp>
29
30#include <pv/widgets/popup.hpp>
31
32using std::enable_shared_from_this;
33using std::shared_ptr;
34
35namespace pv {
36namespace views {
37namespace trace {
38
39const QColor Flag::FillColor(0x73, 0xD2, 0x16);
40
41Flag::Flag(View &view, const pv::util::Timestamp& time, const QString &text) :
42 TimeMarker(view, FillColor, time),
43 text_(text)
44{
45}
46
47Flag::Flag(const Flag &flag) :
48 TimeMarker(flag.view_, FillColor, flag.time_),
49 enable_shared_from_this<Flag>(flag)
50{
51}
52
53bool Flag::enabled() const
54{
55 return true;
56}
57
58QString Flag::get_text() const
59{
60 return text_;
61}
62
63pv::widgets::Popup* Flag::create_popup(QWidget *parent)
64{
65 using pv::widgets::Popup;
66
67 Popup *const popup = TimeMarker::create_popup(parent);
68 popup->set_position(parent->mapToGlobal(
69 drag_point(parent->rect())), Popup::Bottom);
70
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
84QMenu* Flag::create_header_context_menu(QWidget *parent)
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
96void Flag::delete_pressed()
97{
98 on_delete();
99}
100
101void Flag::on_delete()
102{
103 view_.remove_flag(shared_ptr<Flag>(shared_from_this()));
104}
105
106void Flag::on_text_changed(const QString &text)
107{
108 text_ = text;
109 view_.time_item_appearance_changed(true, false);
110}
111
112} // namespace trace
113} // namespace views
114} // namespace pv