blob: d8e2dff3ffc0f76692327314774bc1d586abcc59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
CanvasToolThreshold::CanvasToolThreshold(Canvas *c)
{
canvas = c;
threshold = 0.5;
threshold_is_moving = false;
colThreshold = QColor(255, 127, 127);
colThresholdMoving = QColor(180, 0, 0);
}
bool CanvasToolThreshold::mouseMoveEvent(QMouseEvent *event)
{
if(event->button() != Qt::LeftButton) {
if(abs(event->y() - mapY(threshold)) < 2 ||
abs(event->y() - mapY(-threshold)) < 2 ) {
canvas->setCursor(Qt::SplitVCursor);
return true;
}
}
if(threshold_is_moving) {
float val = unmapY(event->y());
if(fabs(val) > 1.0) val = 1.0;
threshold = fabs(val);
canvas->update();
return true;
}
return false;
}
bool CanvasToolThreshold::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton) {
if(abs(event->y() - mapY(threshold)) < 2 ||
abs(event->y() - mapY(-threshold)) < 2 ) {
threshold_is_moving = true;
canvas->update();
return true;
}
}
return false;
}
bool CanvasToolThreshold::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton) {
if(threshold_is_moving) {
threshold_is_moving = false;
canvas->setCursor(Qt::ArrowCursor);
canvas->update();
emit thresholdChanged(threshold);
return true;
}
}
return false;
}
void CanvasToolThreshold::paintEvent(QPaintEvent *event, QPainter &painter)
{
if(threshold_is_moving) painter.setPen(colThresholdMoving);
else painter.setPen(colThreshold);
painter.drawLine(event->rect().x(), mapY(threshold),
event->rect().x() + event->rect().width(), mapY(threshold));
painter.drawLine(event->rect().x(), mapY(-threshold),
event->rect().x() + event->rect().width(), mapY(-threshold));
}
|