Chris@0
|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 A waveform viewer and audio annotation editor.
|
Chris@3
|
5 Chris Cannam, Queen Mary University of London, 2005-2006
|
Chris@0
|
6
|
Chris@0
|
7 This is experimental software. Not for distribution.
|
Chris@0
|
8 */
|
Chris@0
|
9
|
Chris@0
|
10 #include "TimeValueLayer.h"
|
Chris@0
|
11
|
Chris@0
|
12 #include "base/Model.h"
|
Chris@0
|
13 #include "base/RealTime.h"
|
Chris@0
|
14 #include "base/Profiler.h"
|
Chris@0
|
15 #include "base/View.h"
|
Chris@0
|
16
|
Chris@0
|
17 #include "model/SparseTimeValueModel.h"
|
Chris@0
|
18
|
Chris@0
|
19 #include <QPainter>
|
Chris@6
|
20 #include <QPainterPath>
|
Chris@21
|
21 #include <QMouseEvent>
|
Chris@0
|
22
|
Chris@0
|
23 #include <iostream>
|
Chris@0
|
24 #include <cmath>
|
Chris@0
|
25
|
Chris@0
|
26 TimeValueLayer::TimeValueLayer(View *w) :
|
Chris@0
|
27 Layer(w),
|
Chris@0
|
28 m_model(0),
|
Chris@21
|
29 m_editing(false),
|
Chris@21
|
30 m_editingPoint(0, 0.0, tr("New Point")),
|
Chris@0
|
31 m_colour(Qt::black),
|
Chris@6
|
32 m_plotStyle(PlotConnectedPoints)
|
Chris@0
|
33 {
|
Chris@0
|
34 m_view->addLayer(this);
|
Chris@0
|
35 }
|
Chris@0
|
36
|
Chris@0
|
37 void
|
Chris@0
|
38 TimeValueLayer::setModel(SparseTimeValueModel *model)
|
Chris@0
|
39 {
|
Chris@0
|
40 if (m_model == model) return;
|
Chris@0
|
41 m_model = model;
|
Chris@0
|
42
|
Chris@0
|
43 connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
|
Chris@0
|
44 connect(m_model, SIGNAL(modelChanged(size_t, size_t)),
|
Chris@0
|
45 this, SIGNAL(modelChanged(size_t, size_t)));
|
Chris@0
|
46
|
Chris@0
|
47 connect(m_model, SIGNAL(completionChanged()),
|
Chris@0
|
48 this, SIGNAL(modelCompletionChanged()));
|
Chris@0
|
49
|
Chris@0
|
50 std::cerr << "TimeValueLayer::setModel(" << model << ")" << std::endl;
|
Chris@0
|
51
|
Chris@0
|
52 emit modelReplaced();
|
Chris@0
|
53 }
|
Chris@0
|
54
|
Chris@0
|
55 Layer::PropertyList
|
Chris@0
|
56 TimeValueLayer::getProperties() const
|
Chris@0
|
57 {
|
Chris@0
|
58 PropertyList list;
|
Chris@0
|
59 list.push_back(tr("Colour"));
|
Chris@0
|
60 list.push_back(tr("Plot Type"));
|
Chris@0
|
61 return list;
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 Layer::PropertyType
|
Chris@0
|
65 TimeValueLayer::getPropertyType(const PropertyName &name) const
|
Chris@0
|
66 {
|
Chris@0
|
67 return ValueProperty;
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 int
|
Chris@0
|
71 TimeValueLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@0
|
72 int *min, int *max) const
|
Chris@0
|
73 {
|
Chris@0
|
74 //!!! factor this colour handling stuff out into a colour manager class
|
Chris@0
|
75
|
Chris@0
|
76 int deft = 0;
|
Chris@0
|
77
|
Chris@0
|
78 if (name == tr("Colour")) {
|
Chris@0
|
79
|
Chris@10
|
80 if (min) *min = 0;
|
Chris@10
|
81 if (max) *max = 5;
|
Chris@0
|
82
|
Chris@0
|
83 if (m_colour == Qt::black) deft = 0;
|
Chris@0
|
84 else if (m_colour == Qt::darkRed) deft = 1;
|
Chris@0
|
85 else if (m_colour == Qt::darkBlue) deft = 2;
|
Chris@0
|
86 else if (m_colour == Qt::darkGreen) deft = 3;
|
Chris@0
|
87 else if (m_colour == QColor(200, 50, 255)) deft = 4;
|
Chris@0
|
88 else if (m_colour == QColor(255, 150, 50)) deft = 5;
|
Chris@0
|
89
|
Chris@0
|
90 } else if (name == tr("Plot Type")) {
|
Chris@0
|
91
|
Chris@10
|
92 if (min) *min = 0;
|
Chris@10
|
93 if (max) *max = 4;
|
Chris@0
|
94
|
Chris@0
|
95 deft = int(m_plotStyle);
|
Chris@0
|
96
|
Chris@0
|
97 } else {
|
Chris@0
|
98
|
Chris@0
|
99 deft = Layer::getPropertyRangeAndValue(name, min, max);
|
Chris@0
|
100 }
|
Chris@0
|
101
|
Chris@0
|
102 return deft;
|
Chris@0
|
103 }
|
Chris@0
|
104
|
Chris@0
|
105 QString
|
Chris@0
|
106 TimeValueLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@0
|
107 int value) const
|
Chris@0
|
108 {
|
Chris@0
|
109 if (name == tr("Colour")) {
|
Chris@0
|
110 switch (value) {
|
Chris@0
|
111 default:
|
Chris@0
|
112 case 0: return tr("Black");
|
Chris@0
|
113 case 1: return tr("Red");
|
Chris@0
|
114 case 2: return tr("Blue");
|
Chris@0
|
115 case 3: return tr("Green");
|
Chris@0
|
116 case 4: return tr("Purple");
|
Chris@0
|
117 case 5: return tr("Orange");
|
Chris@0
|
118 }
|
Chris@0
|
119 } else if (name == tr("Plot Type")) {
|
Chris@0
|
120 switch (value) {
|
Chris@0
|
121 default:
|
Chris@0
|
122 case 0: return tr("Points");
|
Chris@0
|
123 case 1: return tr("Stems");
|
Chris@6
|
124 case 2: return tr("Connected Points");
|
Chris@6
|
125 case 3: return tr("Lines");
|
Chris@6
|
126 case 4: return tr("Curve");
|
Chris@0
|
127 }
|
Chris@0
|
128 }
|
Chris@0
|
129 return tr("<unknown>");
|
Chris@0
|
130 }
|
Chris@0
|
131
|
Chris@0
|
132 void
|
Chris@0
|
133 TimeValueLayer::setProperty(const PropertyName &name, int value)
|
Chris@0
|
134 {
|
Chris@0
|
135 if (name == tr("Colour")) {
|
Chris@0
|
136 switch (value) {
|
Chris@0
|
137 default:
|
Chris@0
|
138 case 0: setBaseColour(Qt::black); break;
|
Chris@0
|
139 case 1: setBaseColour(Qt::darkRed); break;
|
Chris@0
|
140 case 2: setBaseColour(Qt::darkBlue); break;
|
Chris@0
|
141 case 3: setBaseColour(Qt::darkGreen); break;
|
Chris@0
|
142 case 4: setBaseColour(QColor(200, 50, 255)); break;
|
Chris@0
|
143 case 5: setBaseColour(QColor(255, 150, 50)); break;
|
Chris@0
|
144 }
|
Chris@0
|
145 } else if (name == tr("Plot Type")) {
|
Chris@0
|
146 setPlotStyle(PlotStyle(value));
|
Chris@0
|
147 }
|
Chris@0
|
148 }
|
Chris@0
|
149
|
Chris@0
|
150 void
|
Chris@0
|
151 TimeValueLayer::setBaseColour(QColor colour)
|
Chris@0
|
152 {
|
Chris@0
|
153 if (m_colour == colour) return;
|
Chris@0
|
154 m_colour = colour;
|
Chris@0
|
155 emit layerParametersChanged();
|
Chris@0
|
156 }
|
Chris@0
|
157
|
Chris@0
|
158 void
|
Chris@0
|
159 TimeValueLayer::setPlotStyle(PlotStyle style)
|
Chris@0
|
160 {
|
Chris@0
|
161 if (m_plotStyle == style) return;
|
Chris@0
|
162 m_plotStyle = style;
|
Chris@0
|
163 emit layerParametersChanged();
|
Chris@0
|
164 }
|
Chris@0
|
165
|
Chris@0
|
166 bool
|
Chris@0
|
167 TimeValueLayer::isLayerScrollable() const
|
Chris@0
|
168 {
|
Chris@6
|
169 // We don't illuminate sections in the line or curve modes, so
|
Chris@6
|
170 // they're always scrollable
|
Chris@6
|
171
|
Chris@6
|
172 if (m_plotStyle == PlotLines ||
|
Chris@6
|
173 m_plotStyle == PlotCurve) return true;
|
Chris@6
|
174
|
Chris@0
|
175 QPoint discard;
|
Chris@0
|
176 return !m_view->shouldIlluminateLocalFeatures(this, discard);
|
Chris@0
|
177 }
|
Chris@0
|
178
|
Chris@0
|
179 QRect
|
Chris@0
|
180 TimeValueLayer::getFeatureDescriptionRect(QPainter &paint, QPoint pos) const
|
Chris@0
|
181 {
|
Chris@0
|
182 return QRect(0, 0,
|
Chris@0
|
183 std::max(100, paint.fontMetrics().width(tr("No local points"))),
|
Chris@0
|
184 70); //!!!
|
Chris@0
|
185 }
|
Chris@0
|
186
|
Chris@0
|
187 //!!! too much in common with TimeInstantLayer
|
Chris@0
|
188
|
Chris@0
|
189 SparseTimeValueModel::PointList
|
Chris@0
|
190 TimeValueLayer::getLocalPoints(int x) const
|
Chris@0
|
191 {
|
Chris@0
|
192 if (!m_model) return SparseTimeValueModel::PointList();
|
Chris@0
|
193
|
Chris@20
|
194 long frame = getFrameForX(x);
|
Chris@0
|
195
|
Chris@0
|
196 SparseTimeValueModel::PointList onPoints =
|
Chris@0
|
197 m_model->getPoints(frame);
|
Chris@0
|
198
|
Chris@0
|
199 if (!onPoints.empty()) {
|
Chris@0
|
200 return onPoints;
|
Chris@0
|
201 }
|
Chris@0
|
202
|
Chris@0
|
203 SparseTimeValueModel::PointList prevPoints =
|
Chris@0
|
204 m_model->getPreviousPoints(frame);
|
Chris@0
|
205 SparseTimeValueModel::PointList nextPoints =
|
Chris@0
|
206 m_model->getNextPoints(frame);
|
Chris@0
|
207
|
Chris@0
|
208 SparseTimeValueModel::PointList usePoints = prevPoints;
|
Chris@0
|
209
|
Chris@0
|
210 if (prevPoints.empty()) {
|
Chris@0
|
211 usePoints = nextPoints;
|
Chris@20
|
212 } else if (prevPoints.begin()->frame < m_view->getStartFrame() &&
|
Chris@20
|
213 !(nextPoints.begin()->frame > m_view->getEndFrame())) {
|
Chris@0
|
214 usePoints = nextPoints;
|
Chris@0
|
215 } else if (nextPoints.begin()->frame - frame <
|
Chris@0
|
216 frame - prevPoints.begin()->frame) {
|
Chris@0
|
217 usePoints = nextPoints;
|
Chris@0
|
218 }
|
Chris@0
|
219
|
Chris@0
|
220 return usePoints;
|
Chris@0
|
221 }
|
Chris@0
|
222
|
Chris@0
|
223 void
|
Chris@0
|
224 TimeValueLayer::paintLocalFeatureDescription(QPainter &paint, QRect rect,
|
Chris@0
|
225 QPoint pos) const
|
Chris@0
|
226 {
|
Chris@0
|
227 //!!! bleagh
|
Chris@0
|
228
|
Chris@0
|
229 int x = pos.x();
|
Chris@0
|
230
|
Chris@0
|
231 if (!m_model || !m_model->getSampleRate()) return;
|
Chris@0
|
232
|
Chris@0
|
233 SparseTimeValueModel::PointList points = getLocalPoints(x);
|
Chris@0
|
234
|
Chris@0
|
235 QFontMetrics metrics = paint.fontMetrics();
|
Chris@0
|
236 int xbase = rect.x() + 5;
|
Chris@0
|
237 int ybase = rect.y() + 5;
|
Chris@0
|
238
|
Chris@0
|
239 if (points.empty()) {
|
Chris@0
|
240 QString label = tr("No local points");
|
Chris@0
|
241 if (!m_model->isReady()) {
|
Chris@0
|
242 label = tr("In progress");
|
Chris@0
|
243 }
|
Chris@0
|
244 paint.drawText(xbase + 5, ybase + 5 + metrics.ascent(), label);
|
Chris@0
|
245 return;
|
Chris@0
|
246 }
|
Chris@0
|
247
|
Chris@0
|
248 long useFrame = points.begin()->frame;
|
Chris@0
|
249
|
Chris@0
|
250 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate());
|
Chris@0
|
251 QString timeText = QString("%1").arg(rt.toText(true).c_str());
|
Chris@0
|
252 QString valueText = QString("%1").arg(points.begin()->value);
|
Chris@0
|
253
|
Chris@0
|
254 int timewidth = metrics.width(timeText);
|
Chris@0
|
255 int valuewidth = metrics.width(valueText);
|
Chris@0
|
256 int labelwidth = metrics.width(points.begin()->label);
|
Chris@0
|
257
|
Chris@0
|
258 int boxheight = metrics.height() * 3 + 4;
|
Chris@0
|
259 int boxwidth = std::max(std::max(timewidth, labelwidth), valuewidth);
|
Chris@0
|
260
|
Chris@0
|
261 paint.drawRect(xbase, ybase, boxwidth + 10,
|
Chris@0
|
262 boxheight + 10 - metrics.descent() + 1);
|
Chris@0
|
263
|
Chris@0
|
264 paint.drawText(xbase + 5, ybase + 5 + metrics.ascent(), timeText);
|
Chris@0
|
265 paint.drawText(xbase + 5, ybase + 7 + metrics.ascent() + metrics.height(),
|
Chris@0
|
266 valueText);
|
Chris@0
|
267 paint.drawText(xbase + 5, ybase + 9 + metrics.ascent() + 2*metrics.height(),
|
Chris@0
|
268 points.begin()->label);
|
Chris@0
|
269 }
|
Chris@0
|
270
|
Chris@13
|
271 int
|
Chris@13
|
272 TimeValueLayer::getNearestFeatureFrame(int frame,
|
Chris@13
|
273 size_t &resolution,
|
Chris@13
|
274 bool snapRight) const
|
Chris@13
|
275 {
|
Chris@13
|
276 if (!m_model) {
|
Chris@13
|
277 return Layer::getNearestFeatureFrame(frame, resolution, snapRight);
|
Chris@13
|
278 }
|
Chris@13
|
279
|
Chris@13
|
280 resolution = m_model->getResolution();
|
Chris@13
|
281 SparseTimeValueModel::PointList points(m_model->getPoints(frame, frame));
|
Chris@13
|
282
|
Chris@13
|
283 int returnFrame = frame;
|
Chris@13
|
284
|
Chris@13
|
285 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@13
|
286 i != points.end(); ++i) {
|
Chris@13
|
287
|
Chris@13
|
288 if (snapRight) {
|
Chris@13
|
289 if (i->frame > frame) {
|
Chris@13
|
290 returnFrame = i->frame;
|
Chris@13
|
291 break;
|
Chris@13
|
292 }
|
Chris@13
|
293 } else {
|
Chris@13
|
294 if (i->frame <= frame) {
|
Chris@13
|
295 returnFrame = i->frame;
|
Chris@13
|
296 }
|
Chris@13
|
297 }
|
Chris@13
|
298 }
|
Chris@13
|
299
|
Chris@13
|
300 return returnFrame;
|
Chris@13
|
301 }
|
Chris@13
|
302
|
Chris@21
|
303 int
|
Chris@21
|
304 TimeValueLayer::getYForValue(float value) const
|
Chris@21
|
305 {
|
Chris@21
|
306 float min = m_model->getValueMinimum();
|
Chris@21
|
307 float max = m_model->getValueMaximum();
|
Chris@21
|
308 if (max == min) max = min + 1.0;
|
Chris@21
|
309
|
Chris@21
|
310 int h = m_view->height();
|
Chris@21
|
311
|
Chris@21
|
312 return int(h - ((value - min) * h) / (max - min));
|
Chris@21
|
313 }
|
Chris@21
|
314
|
Chris@21
|
315 float
|
Chris@21
|
316 TimeValueLayer::getValueForY(int y) const
|
Chris@21
|
317 {
|
Chris@21
|
318 float min = m_model->getValueMinimum();
|
Chris@21
|
319 float max = m_model->getValueMaximum();
|
Chris@21
|
320 if (max == min) max = min + 1.0;
|
Chris@21
|
321
|
Chris@21
|
322 int h = m_view->height();
|
Chris@21
|
323
|
Chris@21
|
324 return min + (float(h - y) * float(max - min)) / h;
|
Chris@21
|
325 }
|
Chris@21
|
326
|
Chris@0
|
327 void
|
Chris@0
|
328 TimeValueLayer::paint(QPainter &paint, QRect rect) const
|
Chris@0
|
329 {
|
Chris@0
|
330 if (!m_model || !m_model->isOK()) return;
|
Chris@0
|
331
|
Chris@0
|
332 int sampleRate = m_model->getSampleRate();
|
Chris@0
|
333 if (!sampleRate) return;
|
Chris@0
|
334
|
Chris@0
|
335 // Profiler profiler("TimeValueLayer::paint", true);
|
Chris@0
|
336
|
Chris@0
|
337 int x0 = rect.left(), x1 = rect.right();
|
Chris@20
|
338 long frame0 = getFrameForX(x0);
|
Chris@20
|
339 long frame1 = getFrameForX(x1);
|
Chris@0
|
340
|
Chris@0
|
341 SparseTimeValueModel::PointList points(m_model->getPoints
|
Chris@0
|
342 (frame0, frame1));
|
Chris@11
|
343 if (points.empty()) return;
|
Chris@0
|
344
|
Chris@0
|
345 paint.setPen(m_colour);
|
Chris@0
|
346
|
Chris@0
|
347 QColor brushColour(m_colour);
|
Chris@0
|
348 brushColour.setAlpha(80);
|
Chris@0
|
349 paint.setBrush(brushColour);
|
Chris@0
|
350
|
Chris@0
|
351 // std::cerr << "TimeValueLayer::paint: resolution is "
|
Chris@0
|
352 // << m_model->getResolution() << " frames" << std::endl;
|
Chris@0
|
353
|
Chris@0
|
354 float min = m_model->getValueMinimum();
|
Chris@0
|
355 float max = m_model->getValueMaximum();
|
Chris@0
|
356 if (max == min) max = min + 1.0;
|
Chris@0
|
357
|
Chris@0
|
358 int origin = int(nearbyint(m_view->height() -
|
Chris@0
|
359 (-min * m_view->height()) / (max - min)));
|
Chris@0
|
360
|
Chris@0
|
361 QPoint localPos;
|
Chris@0
|
362 long illuminateFrame = -1;
|
Chris@0
|
363
|
Chris@0
|
364 if (m_view->shouldIlluminateLocalFeatures(this, localPos)) {
|
Chris@0
|
365 SparseTimeValueModel::PointList localPoints =
|
Chris@0
|
366 getLocalPoints(localPos.x());
|
Chris@0
|
367 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
|
Chris@0
|
368 }
|
Chris@6
|
369
|
Chris@20
|
370 int w =
|
Chris@20
|
371 getXForFrame(frame0 + m_model->getResolution()) -
|
Chris@20
|
372 getXForFrame(frame0);
|
Chris@7
|
373
|
Chris@6
|
374 paint.save();
|
Chris@6
|
375
|
Chris@7
|
376 if (w > 1 &&
|
Chris@7
|
377 (m_plotStyle == PlotLines ||
|
Chris@7
|
378 m_plotStyle == PlotCurve)) {
|
Chris@6
|
379 paint.setRenderHint(QPainter::Antialiasing, true);
|
Chris@6
|
380 }
|
Chris@6
|
381 QPainterPath path;
|
Chris@6
|
382
|
Chris@0
|
383 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@0
|
384 i != points.end(); ++i) {
|
Chris@0
|
385
|
Chris@0
|
386 const SparseTimeValueModel::Point &p(*i);
|
Chris@0
|
387
|
Chris@20
|
388 int x = getXForFrame(p.frame);
|
Chris@21
|
389 int y = getYForValue(p.value);
|
Chris@0
|
390
|
Chris@0
|
391 if (w < 1) w = 1;
|
Chris@0
|
392
|
Chris@6
|
393 if (m_plotStyle == PlotLines ||
|
Chris@6
|
394 m_plotStyle == PlotCurve) {
|
Chris@6
|
395 paint.setPen(m_colour);
|
Chris@6
|
396 paint.setBrush(Qt::NoBrush);
|
Chris@3
|
397 } else {
|
Chris@3
|
398 paint.setPen(m_colour);
|
Chris@6
|
399 paint.setBrush(brushColour);
|
Chris@3
|
400 }
|
Chris@0
|
401
|
Chris@0
|
402 if (m_plotStyle == PlotStems) {
|
Chris@0
|
403 paint.setPen(brushColour);
|
Chris@0
|
404 if (y < origin - 1) {
|
Chris@0
|
405 paint.drawRect(x + w/2, y + 1, 1, origin - y);
|
Chris@0
|
406 } else if (y > origin + 1) {
|
Chris@0
|
407 paint.drawRect(x + w/2, origin, 1, y - origin - 1);
|
Chris@0
|
408 }
|
Chris@0
|
409 paint.setPen(m_colour);
|
Chris@0
|
410 }
|
Chris@0
|
411
|
Chris@0
|
412 if (illuminateFrame == p.frame) {
|
Chris@6
|
413
|
Chris@0
|
414 //!!! aside from the problem of choosing a colour, it'd be
|
Chris@0
|
415 //better to save the highlighted rects and draw them at
|
Chris@0
|
416 //the end perhaps
|
Chris@6
|
417
|
Chris@6
|
418 //!!! not equipped to illuminate the right section in line
|
Chris@6
|
419 //or curve mode
|
Chris@6
|
420
|
Chris@6
|
421 if (m_plotStyle != PlotCurve &&
|
Chris@6
|
422 m_plotStyle != PlotLines) {
|
Chris@6
|
423 paint.setPen(Qt::black);//!!!
|
Chris@6
|
424 paint.setBrush(Qt::black);//!!!
|
Chris@6
|
425 }
|
Chris@0
|
426 }
|
Chris@0
|
427
|
Chris@6
|
428 if (m_plotStyle != PlotLines &&
|
Chris@6
|
429 m_plotStyle != PlotCurve) {
|
Chris@3
|
430 paint.drawRect(x, y - 1, w, 2);
|
Chris@3
|
431 }
|
Chris@0
|
432
|
Chris@6
|
433 if (m_plotStyle == PlotConnectedPoints ||
|
Chris@6
|
434 m_plotStyle == PlotLines ||
|
Chris@6
|
435 m_plotStyle == PlotCurve) {
|
Chris@0
|
436
|
Chris@0
|
437 SparseTimeValueModel::PointList::const_iterator j = i;
|
Chris@0
|
438 ++j;
|
Chris@3
|
439
|
Chris@0
|
440 if (j != points.end()) {
|
Chris@3
|
441
|
Chris@0
|
442 const SparseTimeValueModel::Point &q(*j);
|
Chris@20
|
443 int nx = getXForFrame(q.frame);
|
Chris@21
|
444 int ny = getYForValue(q.value);
|
Chris@3
|
445
|
Chris@6
|
446 if (m_plotStyle == PlotConnectedPoints) {
|
Chris@6
|
447
|
Chris@3
|
448 paint.setPen(brushColour);
|
Chris@3
|
449 paint.drawLine(x + w, y, nx, ny);
|
Chris@6
|
450
|
Chris@6
|
451 } else if (m_plotStyle == PlotLines) {
|
Chris@6
|
452
|
Chris@6
|
453 paint.drawLine(x + w/2, y, nx + w/2, ny);
|
Chris@6
|
454
|
Chris@3
|
455 } else {
|
Chris@6
|
456
|
Chris@6
|
457 if (path.isEmpty()) {
|
Chris@6
|
458 path.moveTo(x + w/2, y);
|
Chris@6
|
459 }
|
Chris@6
|
460
|
Chris@6
|
461 if (nx - x > 5) {
|
Chris@6
|
462 path.cubicTo(x + w, y, nx, ny, nx + w/2, ny);
|
Chris@6
|
463 } else {
|
Chris@6
|
464 path.lineTo(nx + w/2, ny);
|
Chris@6
|
465 }
|
Chris@3
|
466 }
|
Chris@0
|
467 }
|
Chris@0
|
468 }
|
Chris@0
|
469
|
Chris@0
|
470 /// if (p.label != "") {
|
Chris@0
|
471 /// paint.drawText(x + 5, y - paint.fontMetrics().height() + paint.fontMetrics().ascent(), p.label);
|
Chris@0
|
472 /// }
|
Chris@0
|
473 }
|
Chris@6
|
474
|
Chris@6
|
475 if (m_plotStyle == PlotCurve && !path.isEmpty()) {
|
Chris@6
|
476 paint.drawPath(path);
|
Chris@6
|
477 }
|
Chris@6
|
478
|
Chris@6
|
479 paint.restore();
|
Chris@6
|
480
|
Chris@6
|
481 // looks like save/restore doesn't deal with this:
|
Chris@6
|
482 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@6
|
483 }
|
Chris@6
|
484
|
Chris@21
|
485 void
|
Chris@21
|
486 TimeValueLayer::drawStart(QMouseEvent *e)
|
Chris@21
|
487 {
|
Chris@21
|
488 std::cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
489
|
Chris@21
|
490 if (!m_model) return;
|
Chris@21
|
491
|
Chris@21
|
492 long frame = getFrameForX(e->x());
|
Chris@21
|
493 if (frame < 0) frame = 0;
|
Chris@21
|
494 frame = frame / m_model->getResolution() * m_model->getResolution();
|
Chris@21
|
495
|
Chris@21
|
496 float value = getValueForY(e->y());
|
Chris@21
|
497
|
Chris@21
|
498 m_editingPoint = SparseTimeValueModel::Point(frame, value, tr("New Point"));
|
Chris@21
|
499 m_model->addPoint(m_editingPoint);
|
Chris@21
|
500 m_editing = true;
|
Chris@21
|
501 }
|
Chris@21
|
502
|
Chris@21
|
503 void
|
Chris@21
|
504 TimeValueLayer::drawDrag(QMouseEvent *e)
|
Chris@21
|
505 {
|
Chris@21
|
506 std::cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
507
|
Chris@21
|
508 if (!m_model || !m_editing) return;
|
Chris@21
|
509
|
Chris@21
|
510 long frame = getFrameForX(e->x());
|
Chris@21
|
511 if (frame < 0) frame = 0;
|
Chris@21
|
512 frame = frame / m_model->getResolution() * m_model->getResolution();
|
Chris@21
|
513
|
Chris@21
|
514 float value = getValueForY(e->y());
|
Chris@21
|
515
|
Chris@21
|
516 m_model->deletePoint(m_editingPoint);
|
Chris@21
|
517 m_editingPoint.frame = frame;
|
Chris@21
|
518 m_editingPoint.value = value;
|
Chris@21
|
519 m_model->addPoint(m_editingPoint);
|
Chris@21
|
520 }
|
Chris@21
|
521
|
Chris@21
|
522 void
|
Chris@21
|
523 TimeValueLayer::drawEnd(QMouseEvent *e)
|
Chris@21
|
524 {
|
Chris@21
|
525 std::cerr << "TimeValueLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
526 if (!m_model || !m_editing) return;
|
Chris@21
|
527 m_editing = false;
|
Chris@21
|
528 }
|
Chris@21
|
529
|
Chris@21
|
530 void
|
Chris@21
|
531 TimeValueLayer::editStart(QMouseEvent *e)
|
Chris@21
|
532 {
|
Chris@21
|
533 std::cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
534
|
Chris@21
|
535 if (!m_model) return;
|
Chris@21
|
536
|
Chris@21
|
537 SparseTimeValueModel::PointList points = getLocalPoints(e->x());
|
Chris@21
|
538 if (points.empty()) return;
|
Chris@21
|
539
|
Chris@21
|
540 m_editingPoint = *points.begin();
|
Chris@21
|
541 m_editing = true;
|
Chris@21
|
542 }
|
Chris@21
|
543
|
Chris@21
|
544 void
|
Chris@21
|
545 TimeValueLayer::editDrag(QMouseEvent *e)
|
Chris@21
|
546 {
|
Chris@21
|
547 std::cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
548
|
Chris@21
|
549 if (!m_model || !m_editing) return;
|
Chris@21
|
550
|
Chris@21
|
551 long frame = getFrameForX(e->x());
|
Chris@21
|
552 if (frame < 0) frame = 0;
|
Chris@21
|
553 frame = frame / m_model->getResolution() * m_model->getResolution();
|
Chris@21
|
554
|
Chris@21
|
555 float value = getValueForY(e->y());
|
Chris@21
|
556
|
Chris@21
|
557 m_model->deletePoint(m_editingPoint);
|
Chris@21
|
558 m_editingPoint.frame = frame;
|
Chris@21
|
559 m_editingPoint.value = value;
|
Chris@21
|
560 m_model->addPoint(m_editingPoint);
|
Chris@21
|
561 }
|
Chris@21
|
562
|
Chris@21
|
563 void
|
Chris@21
|
564 TimeValueLayer::editEnd(QMouseEvent *e)
|
Chris@21
|
565 {
|
Chris@21
|
566 std::cerr << "TimeValueLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
567 if (!m_model || !m_editing) return;
|
Chris@21
|
568 m_editing = false;
|
Chris@21
|
569 }
|
Chris@21
|
570
|
Chris@6
|
571 QString
|
Chris@6
|
572 TimeValueLayer::toXmlString(QString indent, QString extraAttributes) const
|
Chris@6
|
573 {
|
Chris@6
|
574 return Layer::toXmlString(indent, extraAttributes +
|
Chris@6
|
575 QString(" colour=\"%1\" plotStyle=\"%2\"")
|
Chris@6
|
576 .arg(encodeColour(m_colour)).arg(m_plotStyle));
|
Chris@0
|
577 }
|
Chris@0
|
578
|
Chris@11
|
579 void
|
Chris@11
|
580 TimeValueLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@11
|
581 {
|
Chris@11
|
582 QString colourSpec = attributes.value("colour");
|
Chris@11
|
583 if (colourSpec != "") {
|
Chris@11
|
584 QColor colour(colourSpec);
|
Chris@11
|
585 if (colour.isValid()) {
|
Chris@11
|
586 setBaseColour(QColor(colourSpec));
|
Chris@11
|
587 }
|
Chris@11
|
588 }
|
Chris@11
|
589
|
Chris@11
|
590 bool ok;
|
Chris@11
|
591 PlotStyle style = (PlotStyle)
|
Chris@11
|
592 attributes.value("plotStyle").toInt(&ok);
|
Chris@11
|
593 if (ok) setPlotStyle(style);
|
Chris@11
|
594 }
|
Chris@11
|
595
|
Chris@0
|
596
|
Chris@0
|
597 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
598 #include "TimeValueLayer.moc.cpp"
|
Chris@0
|
599 #endif
|
Chris@0
|
600
|