]> sigrok.org Git - pulseview.git/blame - pv/view/signalscalehandle.cpp
Prefer Qt string multi-arg form over arg chaining.
[pulseview.git] / pv / view / signalscalehandle.cpp
CommitLineData
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
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
21#include <algorithm>
22
23#include <QRadialGradient>
24
25#include "signal.hpp"
26#include "signalscalehandle.hpp"
27#include "tracetreeitemowner.hpp"
28
29using std::max;
30using std::min;
31
32namespace pv {
33namespace view {
34
35SignalScaleHandle::SignalScaleHandle(Signal &owner) :
36 owner_(owner)
37{
38}
39
40bool SignalScaleHandle::enabled() const
41{
42 return selected() || owner_.selected();
43}
44
45void SignalScaleHandle::select(bool select)
46{
47 ViewItem::select(select);
48 owner_.owner()->row_item_appearance_changed(true, true);
49}
50
51void SignalScaleHandle::drag_release()
52{
53 RowItem::drag_release();
54 owner_.scale_handle_released();
55 owner_.owner()->row_item_appearance_changed(true, true);
56}
57
58void 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
65QPoint SignalScaleHandle::point(const QRect &rect) const
66{
67 return owner_.point(rect) + QPoint(0, owner_.scale_handle_offset());
68}
69
70QRectF 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
82void 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
106} // view
107} // pv