]>
Commit | Line | Data |
---|---|---|
f1626bb8 JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2015 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/>. |
f1626bb8 JH |
18 | */ |
19 | ||
20 | #include <algorithm> | |
21 | ||
22 | #include <QRadialGradient> | |
23 | ||
24 | #include "signal.hpp" | |
25 | #include "signalscalehandle.hpp" | |
26 | #include "tracetreeitemowner.hpp" | |
27 | ||
28 | using std::max; | |
29 | using std::min; | |
30 | ||
31 | namespace pv { | |
f4e57597 SA |
32 | namespace views { |
33 | namespace TraceView { | |
f1626bb8 JH |
34 | |
35 | SignalScaleHandle::SignalScaleHandle(Signal &owner) : | |
36 | owner_(owner) | |
37 | { | |
38 | } | |
39 | ||
40 | bool SignalScaleHandle::enabled() const | |
41 | { | |
42 | return selected() || owner_.selected(); | |
43 | } | |
44 | ||
45 | void SignalScaleHandle::select(bool select) | |
46 | { | |
47 | ViewItem::select(select); | |
48 | owner_.owner()->row_item_appearance_changed(true, true); | |
49 | } | |
50 | ||
51 | void SignalScaleHandle::drag_release() | |
52 | { | |
53 | RowItem::drag_release(); | |
54 | owner_.scale_handle_released(); | |
55 | owner_.owner()->row_item_appearance_changed(true, true); | |
56 | } | |
57 | ||
58 | void SignalScaleHandle::drag_by(const QPoint &delta) | |
59 | { | |
60 | owner_.scale_handle_dragged( | |
61 | drag_point_.y() + delta.y() - owner_.get_visual_y()); | |
725568ac | 62 | owner_.owner()->row_item_appearance_changed(true, true); |
f1626bb8 JH |
63 | } |
64 | ||
65 | QPoint SignalScaleHandle::point(const QRect &rect) const | |
66 | { | |
67 | return owner_.point(rect) + QPoint(0, owner_.scale_handle_offset()); | |
68 | } | |
69 | ||
70 | QRectF SignalScaleHandle::hit_box_rect(const ViewItemPaintParams &pp) const | |
71 | { | |
72 | const int text_height = ViewItemPaintParams::text_height(); | |
73 | const double x = -pp.pixels_offset() - text_height / 2; | |
74 | const double min_x = pp.left() + text_height; | |
75 | const double max_x = pp.right() - text_height * 2; | |
76 | return QRectF(min(max(x, min_x), max_x), | |
77 | owner_.get_visual_y() + owner_.scale_handle_offset() - | |
78 | text_height / 2, | |
79 | text_height, text_height); | |
80 | } | |
81 | ||
82 | void SignalScaleHandle::paint_fore(QPainter &p, const ViewItemPaintParams &pp) | |
83 | { | |
84 | if (!enabled()) | |
85 | return; | |
86 | ||
87 | const QRectF r(hit_box_rect(pp)); | |
88 | const QPointF c = (r.topLeft() + 2 * r.center()) / 3; | |
89 | QRadialGradient gradient(c, r.width(), c); | |
90 | ||
91 | if (selected()) { | |
92 | gradient.setColorAt(0.0, QColor(255, 255, 255)); | |
93 | gradient.setColorAt(0.75, QColor(192, 192, 192)); | |
94 | gradient.setColorAt(1.0, QColor(128, 128, 128)); | |
95 | } else { | |
96 | gradient.setColorAt(0.0, QColor(192, 192, 192)); | |
97 | gradient.setColorAt(0.75, QColor(128, 128, 128)); | |
98 | gradient.setColorAt(1.0, QColor(128, 128, 128)); | |
99 | } | |
100 | ||
101 | p.setBrush(QBrush(gradient)); | |
102 | p.setPen(QColor(128, 128, 128)); | |
103 | p.drawEllipse(r); | |
104 | } | |
105 | ||
f4e57597 SA |
106 | } // namespace TraceView |
107 | } // namespace views | |
108 | } // namespace pv |