2 * This file is part of the PulseView project.
4 * Copyright (C) 2015 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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/>.
22 #include <QRadialGradient>
25 #include "signalscalehandle.hpp"
26 #include "tracetreeitemowner.hpp"
35 SignalScaleHandle::SignalScaleHandle(Signal
&owner
) :
40 bool SignalScaleHandle::enabled() const
42 return selected() || owner_
.selected();
45 void SignalScaleHandle::select(bool select
)
47 ViewItem::select(select
);
48 owner_
.owner()->row_item_appearance_changed(true, true);
51 void SignalScaleHandle::drag_release()
53 RowItem::drag_release();
54 owner_
.scale_handle_released();
55 owner_
.owner()->row_item_appearance_changed(true, true);
58 void SignalScaleHandle::drag_by(const QPoint
&delta
)
60 owner_
.scale_handle_dragged(
61 drag_point_
.y() + delta
.y() - owner_
.get_visual_y());
62 owner_
.owner()->row_item_appearance_changed(true, true);
65 QPoint
SignalScaleHandle::point(const QRect
&rect
) const
67 return owner_
.point(rect
) + QPoint(0, owner_
.scale_handle_offset());
70 QRectF
SignalScaleHandle::hit_box_rect(const ViewItemPaintParams
&pp
) const
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() -
79 text_height
, text_height
);
82 void SignalScaleHandle::paint_fore(QPainter
&p
, const ViewItemPaintParams
&pp
)
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
);
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));
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));
101 p
.setBrush(QBrush(gradient
));
102 p
.setPen(QColor(128, 128, 128));
106 } // namespace TraceView