Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@59
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "TimeValueLayer.h"
|
Chris@0
|
17
|
Chris@128
|
18 #include "data/model/Model.h"
|
Chris@0
|
19 #include "base/RealTime.h"
|
Chris@0
|
20 #include "base/Profiler.h"
|
Chris@197
|
21 #include "base/LogRange.h"
|
Chris@437
|
22 #include "base/RangeMapper.h"
|
Chris@376
|
23 #include "ColourDatabase.h"
|
Chris@128
|
24 #include "view/View.h"
|
Chris@0
|
25
|
Chris@128
|
26 #include "data/model/SparseTimeValueModel.h"
|
Chris@340
|
27 #include "data/model/Labeller.h"
|
Chris@0
|
28
|
Chris@70
|
29 #include "widgets/ItemEditDialog.h"
|
Chris@125
|
30 #include "widgets/ListInputDialog.h"
|
Chris@70
|
31
|
Chris@376
|
32 #include "ColourMapper.h"
|
Chris@66
|
33
|
Chris@0
|
34 #include <QPainter>
|
Chris@6
|
35 #include <QPainterPath>
|
Chris@21
|
36 #include <QMouseEvent>
|
Chris@125
|
37 #include <QRegExp>
|
Chris@316
|
38 #include <QTextStream>
|
Chris@360
|
39 #include <QMessageBox>
|
Chris@340
|
40 #include <QInputDialog>
|
Chris@0
|
41
|
Chris@0
|
42 #include <iostream>
|
Chris@0
|
43 #include <cmath>
|
Chris@0
|
44
|
Chris@44
|
45 TimeValueLayer::TimeValueLayer() :
|
Chris@287
|
46 SingleColourLayer(),
|
Chris@0
|
47 m_model(0),
|
Chris@21
|
48 m_editing(false),
|
Chris@23
|
49 m_originalPoint(0, 0.0, tr("New Point")),
|
Chris@21
|
50 m_editingPoint(0, 0.0, tr("New Point")),
|
Chris@22
|
51 m_editingCommand(0),
|
Chris@197
|
52 m_colourMap(0),
|
Chris@66
|
53 m_plotStyle(PlotConnectedPoints),
|
Chris@437
|
54 m_verticalScale(AutoAlignScale),
|
Chris@513
|
55 m_drawSegmentDivisions(true),
|
Chris@437
|
56 m_scaleMinimum(0),
|
Chris@437
|
57 m_scaleMaximum(0)
|
Chris@0
|
58 {
|
Chris@44
|
59
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 void
|
Chris@0
|
63 TimeValueLayer::setModel(SparseTimeValueModel *model)
|
Chris@0
|
64 {
|
Chris@0
|
65 if (m_model == model) return;
|
Chris@0
|
66 m_model = model;
|
Chris@0
|
67
|
Chris@320
|
68 connectSignals(m_model);
|
Chris@0
|
69
|
Chris@438
|
70 m_scaleMinimum = 0;
|
Chris@438
|
71 m_scaleMaximum = 0;
|
Chris@438
|
72
|
Chris@494
|
73 if (m_model && m_model->getRDFTypeURI().endsWith("Segment")) {
|
Chris@494
|
74 setPlotStyle(PlotSegmentation);
|
Chris@494
|
75 }
|
Chris@494
|
76 if (m_model && m_model->getRDFTypeURI().endsWith("Change")) {
|
Chris@494
|
77 setPlotStyle(PlotSegmentation);
|
Chris@494
|
78 }
|
Chris@494
|
79
|
Chris@101
|
80 // std::cerr << "TimeValueLayer::setModel(" << model << ")" << std::endl;
|
Chris@0
|
81
|
Chris@0
|
82 emit modelReplaced();
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@0
|
85 Layer::PropertyList
|
Chris@0
|
86 TimeValueLayer::getProperties() const
|
Chris@0
|
87 {
|
Chris@287
|
88 PropertyList list = SingleColourLayer::getProperties();
|
Chris@87
|
89 list.push_back("Plot Type");
|
Chris@87
|
90 list.push_back("Vertical Scale");
|
Chris@100
|
91 list.push_back("Scale Units");
|
Chris@513
|
92 list.push_back("Draw Segment Division Lines");
|
Chris@0
|
93 return list;
|
Chris@0
|
94 }
|
Chris@0
|
95
|
Chris@87
|
96 QString
|
Chris@87
|
97 TimeValueLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@87
|
98 {
|
Chris@87
|
99 if (name == "Plot Type") return tr("Plot Type");
|
Chris@87
|
100 if (name == "Vertical Scale") return tr("Vertical Scale");
|
Chris@100
|
101 if (name == "Scale Units") return tr("Scale Units");
|
Chris@513
|
102 if (name == "Draw Segment Division Lines") return tr("Draw Segment Division Lines");
|
Chris@287
|
103 return SingleColourLayer::getPropertyLabel(name);
|
Chris@87
|
104 }
|
Chris@87
|
105
|
Chris@515
|
106 QString
|
Chris@515
|
107 TimeValueLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@515
|
108 {
|
Chris@515
|
109 if (name == "Draw Segment Division Lines") return "lines";
|
Chris@515
|
110 return "";
|
Chris@515
|
111 }
|
Chris@515
|
112
|
Chris@0
|
113 Layer::PropertyType
|
Chris@0
|
114 TimeValueLayer::getPropertyType(const PropertyName &name) const
|
Chris@0
|
115 {
|
Chris@287
|
116 if (name == "Plot Type") return ValueProperty;
|
Chris@287
|
117 if (name == "Vertical Scale") return ValueProperty;
|
Chris@100
|
118 if (name == "Scale Units") return UnitsProperty;
|
Chris@287
|
119 if (name == "Colour" && m_plotStyle == PlotSegmentation) return ValueProperty;
|
Chris@513
|
120 if (name == "Draw Segment Division Lines") return ToggleProperty;
|
Chris@287
|
121 return SingleColourLayer::getPropertyType(name);
|
Chris@0
|
122 }
|
Chris@0
|
123
|
Chris@198
|
124 QString
|
Chris@198
|
125 TimeValueLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@198
|
126 {
|
Chris@198
|
127 if (name == "Vertical Scale" || name == "Scale Units") {
|
Chris@198
|
128 return tr("Scale");
|
Chris@198
|
129 }
|
Chris@513
|
130 if (name == "Plot Type" || name == "Draw Segment Division Lines") {
|
Chris@513
|
131 return tr("Plot Type");
|
Chris@513
|
132 }
|
Chris@287
|
133 return SingleColourLayer::getPropertyGroupName(name);
|
Chris@198
|
134 }
|
Chris@198
|
135
|
Chris@0
|
136 int
|
Chris@0
|
137 TimeValueLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
138 int *min, int *max, int *deflt) const
|
Chris@0
|
139 {
|
Chris@216
|
140 int val = 0;
|
Chris@0
|
141
|
Chris@287
|
142 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
|
Chris@197
|
143
|
Chris@287
|
144 if (min) *min = 0;
|
Chris@287
|
145 if (max) *max = ColourMapper::getColourMapCount() - 1;
|
Chris@287
|
146 if (deflt) *deflt = 0;
|
Chris@197
|
147
|
Chris@287
|
148 val = m_colourMap;
|
Chris@0
|
149
|
Chris@87
|
150 } else if (name == "Plot Type") {
|
Chris@0
|
151
|
Chris@10
|
152 if (min) *min = 0;
|
Chris@26
|
153 if (max) *max = 5;
|
Chris@216
|
154 if (deflt) *deflt = int(PlotConnectedPoints);
|
Chris@0
|
155
|
Chris@216
|
156 val = int(m_plotStyle);
|
Chris@0
|
157
|
Chris@87
|
158 } else if (name == "Vertical Scale") {
|
Chris@66
|
159
|
Chris@66
|
160 if (min) *min = 0;
|
Chris@66
|
161 if (max) *max = 3;
|
Chris@216
|
162 if (deflt) *deflt = int(AutoAlignScale);
|
Chris@66
|
163
|
Chris@216
|
164 val = int(m_verticalScale);
|
Chris@66
|
165
|
Chris@100
|
166 } else if (name == "Scale Units") {
|
Chris@100
|
167
|
Chris@216
|
168 if (deflt) *deflt = 0;
|
Chris@100
|
169 if (m_model) {
|
Chris@216
|
170 val = UnitDatabase::getInstance()->getUnitId
|
Chris@100
|
171 (m_model->getScaleUnits());
|
Chris@100
|
172 }
|
Chris@100
|
173
|
Chris@513
|
174 } else if (name == "Draw Segment Division Lines") {
|
Chris@513
|
175
|
Chris@513
|
176 if (min) *min = 0;
|
Chris@513
|
177 if (max) *max = 0;
|
Chris@513
|
178 if (deflt) *deflt = 1;
|
Chris@513
|
179 val = (m_drawSegmentDivisions ? 1.0 : 0.0);
|
Chris@513
|
180
|
Chris@0
|
181 } else {
|
Chris@0
|
182
|
Chris@287
|
183 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@0
|
184 }
|
Chris@0
|
185
|
Chris@216
|
186 return val;
|
Chris@0
|
187 }
|
Chris@0
|
188
|
Chris@0
|
189 QString
|
Chris@0
|
190 TimeValueLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@0
|
191 int value) const
|
Chris@0
|
192 {
|
Chris@287
|
193 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
|
Chris@287
|
194 return ColourMapper::getColourMapName(value);
|
Chris@87
|
195 } else if (name == "Plot Type") {
|
Chris@0
|
196 switch (value) {
|
Chris@0
|
197 default:
|
Chris@0
|
198 case 0: return tr("Points");
|
Chris@0
|
199 case 1: return tr("Stems");
|
Chris@6
|
200 case 2: return tr("Connected Points");
|
Chris@6
|
201 case 3: return tr("Lines");
|
Chris@6
|
202 case 4: return tr("Curve");
|
Chris@26
|
203 case 5: return tr("Segmentation");
|
Chris@0
|
204 }
|
Chris@87
|
205 } else if (name == "Vertical Scale") {
|
Chris@66
|
206 switch (value) {
|
Chris@66
|
207 default:
|
Chris@101
|
208 case 0: return tr("Auto-Align");
|
Chris@198
|
209 case 1: return tr("Linear");
|
Chris@198
|
210 case 2: return tr("Log");
|
Chris@198
|
211 case 3: return tr("+/-1");
|
Chris@66
|
212 }
|
Chris@0
|
213 }
|
Chris@287
|
214 return SingleColourLayer::getPropertyValueLabel(name, value);
|
Chris@0
|
215 }
|
Chris@0
|
216
|
Chris@0
|
217 void
|
Chris@0
|
218 TimeValueLayer::setProperty(const PropertyName &name, int value)
|
Chris@0
|
219 {
|
Chris@287
|
220 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
|
Chris@287
|
221 setFillColourMap(value);
|
Chris@87
|
222 } else if (name == "Plot Type") {
|
Chris@0
|
223 setPlotStyle(PlotStyle(value));
|
Chris@87
|
224 } else if (name == "Vertical Scale") {
|
Chris@66
|
225 setVerticalScale(VerticalScale(value));
|
Chris@100
|
226 } else if (name == "Scale Units") {
|
Chris@100
|
227 if (m_model) {
|
Chris@100
|
228 m_model->setScaleUnits
|
Chris@100
|
229 (UnitDatabase::getInstance()->getUnitById(value));
|
Chris@100
|
230 emit modelChanged();
|
Chris@100
|
231 }
|
Chris@513
|
232 } else if (name == "Draw Segment Division Lines") {
|
Chris@513
|
233 setDrawSegmentDivisions(value > 0.5);
|
Chris@287
|
234 } else {
|
Chris@287
|
235 SingleColourLayer::setProperty(name, value);
|
Chris@0
|
236 }
|
Chris@0
|
237 }
|
Chris@0
|
238
|
Chris@0
|
239 void
|
Chris@197
|
240 TimeValueLayer::setFillColourMap(int map)
|
Chris@197
|
241 {
|
Chris@197
|
242 if (m_colourMap == map) return;
|
Chris@197
|
243 m_colourMap = map;
|
Chris@197
|
244 emit layerParametersChanged();
|
Chris@197
|
245 }
|
Chris@197
|
246
|
Chris@197
|
247 void
|
Chris@0
|
248 TimeValueLayer::setPlotStyle(PlotStyle style)
|
Chris@0
|
249 {
|
Chris@0
|
250 if (m_plotStyle == style) return;
|
Chris@197
|
251 bool colourTypeChanged = (style == PlotSegmentation ||
|
Chris@197
|
252 m_plotStyle == PlotSegmentation);
|
Chris@0
|
253 m_plotStyle = style;
|
Chris@197
|
254 if (colourTypeChanged) {
|
Chris@197
|
255 emit layerParameterRangesChanged();
|
Chris@197
|
256 }
|
Chris@0
|
257 emit layerParametersChanged();
|
Chris@0
|
258 }
|
Chris@0
|
259
|
Chris@66
|
260 void
|
Chris@66
|
261 TimeValueLayer::setVerticalScale(VerticalScale scale)
|
Chris@66
|
262 {
|
Chris@66
|
263 if (m_verticalScale == scale) return;
|
Chris@66
|
264 m_verticalScale = scale;
|
Chris@66
|
265 emit layerParametersChanged();
|
Chris@66
|
266 }
|
Chris@66
|
267
|
Chris@513
|
268 void
|
Chris@513
|
269 TimeValueLayer::setDrawSegmentDivisions(bool draw)
|
Chris@513
|
270 {
|
Chris@513
|
271 if (m_drawSegmentDivisions == draw) return;
|
Chris@513
|
272 m_drawSegmentDivisions = draw;
|
Chris@513
|
273 emit layerParametersChanged();
|
Chris@513
|
274 }
|
Chris@513
|
275
|
Chris@0
|
276 bool
|
Chris@44
|
277 TimeValueLayer::isLayerScrollable(const View *v) const
|
Chris@0
|
278 {
|
Chris@6
|
279 // We don't illuminate sections in the line or curve modes, so
|
Chris@6
|
280 // they're always scrollable
|
Chris@6
|
281
|
Chris@6
|
282 if (m_plotStyle == PlotLines ||
|
Chris@6
|
283 m_plotStyle == PlotCurve) return true;
|
Chris@6
|
284
|
Chris@0
|
285 QPoint discard;
|
Chris@44
|
286 return !v->shouldIlluminateLocalFeatures(this, discard);
|
Chris@0
|
287 }
|
Chris@0
|
288
|
Chris@79
|
289 bool
|
Chris@101
|
290 TimeValueLayer::getValueExtents(float &min, float &max,
|
Chris@101
|
291 bool &logarithmic, QString &unit) const
|
Chris@79
|
292 {
|
Chris@101
|
293 if (!m_model) return false;
|
Chris@79
|
294 min = m_model->getValueMinimum();
|
Chris@79
|
295 max = m_model->getValueMaximum();
|
Chris@101
|
296 logarithmic = (m_verticalScale == LogScale);
|
Chris@79
|
297 unit = m_model->getScaleUnits();
|
Chris@79
|
298 return true;
|
Chris@79
|
299 }
|
Chris@79
|
300
|
Chris@101
|
301 bool
|
Chris@101
|
302 TimeValueLayer::getDisplayExtents(float &min, float &max) const
|
Chris@101
|
303 {
|
Chris@296
|
304 if (!m_model || shouldAutoAlign()) return false;
|
Chris@101
|
305
|
Chris@437
|
306 if (m_scaleMinimum == m_scaleMaximum) {
|
Chris@455
|
307 min = m_model->getValueMinimum();
|
Chris@455
|
308 max = m_model->getValueMaximum();
|
Chris@455
|
309 return true;
|
Chris@437
|
310 }
|
Chris@437
|
311
|
Chris@437
|
312 min = m_scaleMinimum;
|
Chris@437
|
313 max = m_scaleMaximum;
|
Chris@437
|
314
|
Chris@437
|
315 // std::cerr << "TimeValueLayer::getDisplayExtents: min = " << min << ", max = " << max << std::endl;
|
Chris@437
|
316
|
Chris@101
|
317 return true;
|
Chris@101
|
318 }
|
Chris@101
|
319
|
Chris@437
|
320 bool
|
Chris@437
|
321 TimeValueLayer::setDisplayExtents(float min, float max)
|
Chris@437
|
322 {
|
Chris@437
|
323 if (!m_model) return false;
|
Chris@437
|
324
|
Chris@437
|
325 if (min == max) {
|
Chris@437
|
326 if (min == 0.f) {
|
Chris@437
|
327 max = 1.f;
|
Chris@437
|
328 } else {
|
Chris@437
|
329 max = min * 1.0001;
|
Chris@437
|
330 }
|
Chris@437
|
331 }
|
Chris@437
|
332
|
Chris@437
|
333 m_scaleMinimum = min;
|
Chris@437
|
334 m_scaleMaximum = max;
|
Chris@437
|
335
|
Chris@438
|
336 // std::cerr << "TimeValueLayer::setDisplayExtents: min = " << min << ", max = " << max << std::endl;
|
Chris@437
|
337
|
Chris@437
|
338 emit layerParametersChanged();
|
Chris@437
|
339 return true;
|
Chris@437
|
340 }
|
Chris@437
|
341
|
Chris@437
|
342 int
|
Chris@437
|
343 TimeValueLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@437
|
344 {
|
Chris@437
|
345 if (shouldAutoAlign()) return 0;
|
Chris@437
|
346 if (!m_model) return 0;
|
Chris@437
|
347
|
Chris@439
|
348 defaultStep = 0;
|
Chris@437
|
349 return 100;
|
Chris@437
|
350 }
|
Chris@437
|
351
|
Chris@437
|
352 int
|
Chris@437
|
353 TimeValueLayer::getCurrentVerticalZoomStep() const
|
Chris@437
|
354 {
|
Chris@437
|
355 if (shouldAutoAlign()) return 0;
|
Chris@437
|
356 if (!m_model) return 0;
|
Chris@437
|
357
|
Chris@437
|
358 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
|
Chris@437
|
359 if (!mapper) return 0;
|
Chris@437
|
360
|
Chris@437
|
361 float dmin, dmax;
|
Chris@437
|
362 getDisplayExtents(dmin, dmax);
|
Chris@437
|
363
|
Chris@437
|
364 int nr = mapper->getPositionForValue(dmax - dmin);
|
Chris@437
|
365 /*
|
Chris@437
|
366 int n0 = mapper->getPositionForValue(dmax);
|
Chris@437
|
367 int n1 = mapper->getPositionForValue(dmin);
|
Chris@437
|
368 int nr = n1 - n0;
|
Chris@437
|
369 if (nr < 0) nr = -nr;
|
Chris@437
|
370
|
Chris@437
|
371 std::cerr << "TimeValueLayer::getCurrentVerticalZoomStep: dmin = " << dmin << ", dmax = " << dmax << ", n0 = " << n0 << ", n1 = " << n1 << ", nr = " << nr << std::endl;
|
Chris@437
|
372 */
|
Chris@437
|
373 delete mapper;
|
Chris@437
|
374
|
Chris@437
|
375 return 100 - nr;
|
Chris@437
|
376 }
|
Chris@437
|
377
|
Chris@437
|
378 void
|
Chris@437
|
379 TimeValueLayer::setVerticalZoomStep(int step)
|
Chris@437
|
380 {
|
Chris@437
|
381 if (shouldAutoAlign()) return;
|
Chris@437
|
382 if (!m_model) return;
|
Chris@437
|
383
|
Chris@437
|
384 RangeMapper *mapper = getNewVerticalZoomRangeMapper();
|
Chris@437
|
385 if (!mapper) return;
|
Chris@437
|
386
|
Chris@437
|
387 float min, max;
|
Chris@437
|
388 bool logarithmic;
|
Chris@437
|
389 QString unit;
|
Chris@437
|
390 getValueExtents(min, max, logarithmic, unit);
|
Chris@437
|
391
|
Chris@437
|
392 float dmin, dmax;
|
Chris@437
|
393 getDisplayExtents(dmin, dmax);
|
Chris@437
|
394
|
Chris@437
|
395 float newdist = mapper->getValueForPosition(100 - step);
|
Chris@437
|
396
|
Chris@437
|
397 float newmin, newmax;
|
Chris@437
|
398
|
Chris@437
|
399 if (logarithmic) {
|
Chris@437
|
400
|
Chris@437
|
401 // see SpectrogramLayer::setVerticalZoomStep
|
Chris@437
|
402
|
Chris@437
|
403 newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2;
|
Chris@437
|
404 newmin = newmax - newdist;
|
Chris@437
|
405
|
Chris@437
|
406 // std::cerr << "newmin = " << newmin << ", newmax = " << newmax << std::endl;
|
Chris@437
|
407
|
Chris@437
|
408 } else {
|
Chris@437
|
409 float dmid = (dmax + dmin) / 2;
|
Chris@437
|
410 newmin = dmid - newdist / 2;
|
Chris@437
|
411 newmax = dmid + newdist / 2;
|
Chris@437
|
412 }
|
Chris@437
|
413
|
Chris@437
|
414 if (newmin < min) {
|
Chris@437
|
415 newmax += (min - newmin);
|
Chris@437
|
416 newmin = min;
|
Chris@437
|
417 }
|
Chris@437
|
418 if (newmax > max) {
|
Chris@437
|
419 newmax = max;
|
Chris@437
|
420 }
|
Chris@437
|
421
|
Chris@437
|
422 std::cerr << "TimeValueLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << std::endl;
|
Chris@437
|
423
|
Chris@437
|
424 setDisplayExtents(newmin, newmax);
|
Chris@437
|
425 }
|
Chris@437
|
426
|
Chris@437
|
427 RangeMapper *
|
Chris@437
|
428 TimeValueLayer::getNewVerticalZoomRangeMapper() const
|
Chris@437
|
429 {
|
Chris@437
|
430 if (!m_model) return 0;
|
Chris@437
|
431
|
Chris@437
|
432 RangeMapper *mapper;
|
Chris@437
|
433
|
Chris@437
|
434 float min, max;
|
Chris@437
|
435 bool logarithmic;
|
Chris@437
|
436 QString unit;
|
Chris@437
|
437 getValueExtents(min, max, logarithmic, unit);
|
Chris@437
|
438
|
Chris@437
|
439 if (min == max) return 0;
|
Chris@437
|
440
|
Chris@437
|
441 if (logarithmic) {
|
Chris@437
|
442 mapper = new LogRangeMapper(0, 100, min, max, unit);
|
Chris@437
|
443 } else {
|
Chris@437
|
444 mapper = new LinearRangeMapper(0, 100, min, max, unit);
|
Chris@437
|
445 }
|
Chris@437
|
446
|
Chris@437
|
447 return mapper;
|
Chris@437
|
448 }
|
Chris@437
|
449
|
Chris@0
|
450 SparseTimeValueModel::PointList
|
Chris@44
|
451 TimeValueLayer::getLocalPoints(View *v, int x) const
|
Chris@0
|
452 {
|
Chris@0
|
453 if (!m_model) return SparseTimeValueModel::PointList();
|
Chris@0
|
454
|
Chris@44
|
455 long frame = v->getFrameForX(x);
|
Chris@0
|
456
|
Chris@0
|
457 SparseTimeValueModel::PointList onPoints =
|
Chris@0
|
458 m_model->getPoints(frame);
|
Chris@0
|
459
|
Chris@0
|
460 if (!onPoints.empty()) {
|
Chris@0
|
461 return onPoints;
|
Chris@0
|
462 }
|
Chris@0
|
463
|
Chris@0
|
464 SparseTimeValueModel::PointList prevPoints =
|
Chris@0
|
465 m_model->getPreviousPoints(frame);
|
Chris@0
|
466 SparseTimeValueModel::PointList nextPoints =
|
Chris@0
|
467 m_model->getNextPoints(frame);
|
Chris@0
|
468
|
Chris@0
|
469 SparseTimeValueModel::PointList usePoints = prevPoints;
|
Chris@0
|
470
|
Chris@0
|
471 if (prevPoints.empty()) {
|
Chris@0
|
472 usePoints = nextPoints;
|
Chris@248
|
473 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
|
Chris@44
|
474 !(nextPoints.begin()->frame > v->getEndFrame())) {
|
Chris@0
|
475 usePoints = nextPoints;
|
Chris@0
|
476 } else if (nextPoints.begin()->frame - frame <
|
Chris@0
|
477 frame - prevPoints.begin()->frame) {
|
Chris@0
|
478 usePoints = nextPoints;
|
Chris@0
|
479 }
|
Chris@0
|
480
|
Chris@28
|
481 if (!usePoints.empty()) {
|
Chris@28
|
482 int fuzz = 2;
|
Chris@44
|
483 int px = v->getXForFrame(usePoints.begin()->frame);
|
Chris@28
|
484 if ((px > x && px - x > fuzz) ||
|
Chris@28
|
485 (px < x && x - px > fuzz + 1)) {
|
Chris@28
|
486 usePoints.clear();
|
Chris@28
|
487 }
|
Chris@28
|
488 }
|
Chris@28
|
489
|
Chris@0
|
490 return usePoints;
|
Chris@0
|
491 }
|
Chris@0
|
492
|
Chris@25
|
493 QString
|
Chris@44
|
494 TimeValueLayer::getFeatureDescription(View *v, QPoint &pos) const
|
Chris@0
|
495 {
|
Chris@25
|
496 int x = pos.x();
|
Chris@0
|
497
|
Chris@25
|
498 if (!m_model || !m_model->getSampleRate()) return "";
|
Chris@0
|
499
|
Chris@44
|
500 SparseTimeValueModel::PointList points = getLocalPoints(v, x);
|
Chris@0
|
501
|
Chris@0
|
502 if (points.empty()) {
|
Chris@0
|
503 if (!m_model->isReady()) {
|
Chris@25
|
504 return tr("In progress");
|
Chris@25
|
505 } else {
|
Chris@25
|
506 return tr("No local points");
|
Chris@0
|
507 }
|
Chris@0
|
508 }
|
Chris@0
|
509
|
Chris@0
|
510 long useFrame = points.begin()->frame;
|
Chris@0
|
511
|
Chris@0
|
512 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate());
|
Chris@25
|
513
|
Chris@25
|
514 QString text;
|
Chris@101
|
515 QString unit = m_model->getScaleUnits();
|
Chris@101
|
516 if (unit != "") unit = " " + unit;
|
Chris@0
|
517
|
Chris@25
|
518 if (points.begin()->label == "") {
|
Chris@101
|
519 text = QString(tr("Time:\t%1\nValue:\t%2%3\nNo label"))
|
Chris@25
|
520 .arg(rt.toText(true).c_str())
|
Chris@25
|
521 .arg(points.begin()->value)
|
Chris@101
|
522 .arg(unit);
|
Chris@101
|
523 } else {
|
Chris@101
|
524 text = QString(tr("Time:\t%1\nValue:\t%2%3\nLabel:\t%4"))
|
Chris@101
|
525 .arg(rt.toText(true).c_str())
|
Chris@101
|
526 .arg(points.begin()->value)
|
Chris@101
|
527 .arg(unit)
|
Chris@25
|
528 .arg(points.begin()->label);
|
Chris@25
|
529 }
|
Chris@0
|
530
|
Chris@44
|
531 pos = QPoint(v->getXForFrame(useFrame),
|
Chris@44
|
532 getYForValue(v, points.begin()->value));
|
Chris@25
|
533 return text;
|
Chris@0
|
534 }
|
Chris@0
|
535
|
Chris@28
|
536 bool
|
Chris@44
|
537 TimeValueLayer::snapToFeatureFrame(View *v, int &frame,
|
Chris@28
|
538 size_t &resolution,
|
Chris@28
|
539 SnapType snap) const
|
Chris@13
|
540 {
|
Chris@13
|
541 if (!m_model) {
|
Chris@44
|
542 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
|
Chris@13
|
543 }
|
Chris@13
|
544
|
Chris@13
|
545 resolution = m_model->getResolution();
|
Chris@28
|
546 SparseTimeValueModel::PointList points;
|
Chris@13
|
547
|
Chris@28
|
548 if (snap == SnapNeighbouring) {
|
Chris@28
|
549
|
Chris@44
|
550 points = getLocalPoints(v, v->getXForFrame(frame));
|
Chris@28
|
551 if (points.empty()) return false;
|
Chris@28
|
552 frame = points.begin()->frame;
|
Chris@28
|
553 return true;
|
Chris@28
|
554 }
|
Chris@28
|
555
|
Chris@28
|
556 points = m_model->getPoints(frame, frame);
|
Chris@28
|
557 int snapped = frame;
|
Chris@28
|
558 bool found = false;
|
Chris@13
|
559
|
Chris@13
|
560 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@13
|
561 i != points.end(); ++i) {
|
Chris@13
|
562
|
Chris@28
|
563 if (snap == SnapRight) {
|
Chris@28
|
564
|
Chris@13
|
565 if (i->frame > frame) {
|
Chris@28
|
566 snapped = i->frame;
|
Chris@28
|
567 found = true;
|
Chris@13
|
568 break;
|
Chris@13
|
569 }
|
Chris@28
|
570
|
Chris@28
|
571 } else if (snap == SnapLeft) {
|
Chris@28
|
572
|
Chris@13
|
573 if (i->frame <= frame) {
|
Chris@28
|
574 snapped = i->frame;
|
Chris@28
|
575 found = true; // don't break, as the next may be better
|
Chris@28
|
576 } else {
|
Chris@28
|
577 break;
|
Chris@28
|
578 }
|
Chris@28
|
579
|
Chris@28
|
580 } else { // nearest
|
Chris@28
|
581
|
Chris@28
|
582 SparseTimeValueModel::PointList::const_iterator j = i;
|
Chris@28
|
583 ++j;
|
Chris@28
|
584
|
Chris@28
|
585 if (j == points.end()) {
|
Chris@28
|
586
|
Chris@28
|
587 snapped = i->frame;
|
Chris@28
|
588 found = true;
|
Chris@28
|
589 break;
|
Chris@28
|
590
|
Chris@28
|
591 } else if (j->frame >= frame) {
|
Chris@28
|
592
|
Chris@28
|
593 if (j->frame - frame < frame - i->frame) {
|
Chris@28
|
594 snapped = j->frame;
|
Chris@28
|
595 } else {
|
Chris@28
|
596 snapped = i->frame;
|
Chris@28
|
597 }
|
Chris@28
|
598 found = true;
|
Chris@28
|
599 break;
|
Chris@13
|
600 }
|
Chris@13
|
601 }
|
Chris@13
|
602 }
|
Chris@13
|
603
|
Chris@28
|
604 frame = snapped;
|
Chris@28
|
605 return found;
|
Chris@13
|
606 }
|
Chris@13
|
607
|
Chris@517
|
608 bool
|
Chris@517
|
609 TimeValueLayer::snapToSimilarFeature(View *v, int &frame,
|
Chris@517
|
610 size_t &resolution,
|
Chris@517
|
611 SnapType snap) const
|
Chris@517
|
612 {
|
Chris@517
|
613 if (!m_model) {
|
Chris@517
|
614 return Layer::snapToSimilarFeature(v, frame, resolution, snap);
|
Chris@517
|
615 }
|
Chris@517
|
616
|
Chris@517
|
617 resolution = m_model->getResolution();
|
Chris@517
|
618
|
Chris@517
|
619 const SparseTimeValueModel::PointList &points = m_model->getPoints();
|
Chris@517
|
620 SparseTimeValueModel::PointList close = m_model->getPoints(frame, frame);
|
Chris@517
|
621
|
Chris@517
|
622 SparseTimeValueModel::PointList::const_iterator i;
|
Chris@517
|
623
|
Chris@517
|
624 int matchframe = frame;
|
Chris@517
|
625 float matchvalue = 0.f;
|
Chris@517
|
626
|
Chris@517
|
627 for (i = close.begin(); i != close.end(); ++i) {
|
Chris@517
|
628 if (i->frame > frame) break;
|
Chris@517
|
629 matchvalue = i->value;
|
Chris@517
|
630 matchframe = i->frame;
|
Chris@517
|
631 }
|
Chris@517
|
632
|
Chris@517
|
633 int snapped = frame;
|
Chris@517
|
634 bool found = false;
|
Chris@517
|
635 bool distant = false;
|
Chris@517
|
636 float epsilon = 0.0001;
|
Chris@517
|
637
|
Chris@517
|
638 i = close.begin();
|
Chris@517
|
639
|
Chris@517
|
640 // Scan through the close points first, then the more distant ones
|
Chris@517
|
641 // if no suitable close one is found
|
Chris@517
|
642
|
Chris@517
|
643 while (i != points.end()) {
|
Chris@517
|
644
|
Chris@517
|
645 if (i == close.end()) {
|
Chris@517
|
646 i = points.begin();
|
Chris@517
|
647 distant = true;
|
Chris@517
|
648 }
|
Chris@517
|
649
|
Chris@517
|
650 if (snap == SnapRight) {
|
Chris@517
|
651
|
Chris@517
|
652 if (i->frame > matchframe &&
|
Chris@517
|
653 fabsf(i->value - matchvalue) < epsilon) {
|
Chris@517
|
654 snapped = i->frame;
|
Chris@517
|
655 found = true;
|
Chris@517
|
656 break;
|
Chris@517
|
657 }
|
Chris@517
|
658
|
Chris@517
|
659 } else if (snap == SnapLeft) {
|
Chris@517
|
660
|
Chris@517
|
661 if (i->frame < matchframe) {
|
Chris@517
|
662 if (fabsf(i->value - matchvalue) < epsilon) {
|
Chris@517
|
663 snapped = i->frame;
|
Chris@517
|
664 found = true; // don't break, as the next may be better
|
Chris@517
|
665 }
|
Chris@517
|
666 } else if (found || distant) {
|
Chris@517
|
667 break;
|
Chris@517
|
668 }
|
Chris@517
|
669
|
Chris@517
|
670 } else {
|
Chris@517
|
671 // no other snap types supported
|
Chris@517
|
672 }
|
Chris@517
|
673
|
Chris@517
|
674 ++i;
|
Chris@517
|
675 }
|
Chris@517
|
676
|
Chris@517
|
677 frame = snapped;
|
Chris@517
|
678 return found;
|
Chris@517
|
679 }
|
Chris@517
|
680
|
Chris@101
|
681 void
|
Chris@101
|
682 TimeValueLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const
|
Chris@101
|
683 {
|
Chris@101
|
684 min = 0.0;
|
Chris@101
|
685 max = 0.0;
|
Chris@101
|
686 log = false;
|
Chris@101
|
687
|
Chris@296
|
688 if (shouldAutoAlign()) {
|
Chris@101
|
689
|
Chris@101
|
690 if (!v->getValueExtents(m_model->getScaleUnits(), min, max, log)) {
|
Chris@101
|
691 min = m_model->getValueMinimum();
|
Chris@101
|
692 max = m_model->getValueMaximum();
|
Chris@101
|
693 } else if (log) {
|
Chris@197
|
694 LogRange::mapRange(min, max);
|
Chris@101
|
695 }
|
Chris@101
|
696
|
Chris@101
|
697 } else if (m_verticalScale == PlusMinusOneScale) {
|
Chris@101
|
698
|
Chris@101
|
699 min = -1.0;
|
Chris@101
|
700 max = 1.0;
|
Chris@101
|
701
|
Chris@101
|
702 } else {
|
Chris@101
|
703
|
Chris@437
|
704 getDisplayExtents(min, max);
|
Chris@101
|
705
|
Chris@101
|
706 if (m_verticalScale == LogScale) {
|
Chris@197
|
707 LogRange::mapRange(min, max);
|
Chris@101
|
708 log = true;
|
Chris@101
|
709 }
|
Chris@101
|
710 }
|
Chris@101
|
711
|
Chris@101
|
712 if (max == min) max = min + 1.0;
|
Chris@101
|
713 }
|
Chris@101
|
714
|
Chris@21
|
715 int
|
Chris@66
|
716 TimeValueLayer::getYForValue(View *v, float val) const
|
Chris@21
|
717 {
|
Chris@79
|
718 float min = 0.0, max = 0.0;
|
Chris@101
|
719 bool logarithmic = false;
|
Chris@79
|
720 int h = v->height();
|
Chris@79
|
721
|
Chris@101
|
722 getScaleExtents(v, min, max, logarithmic);
|
Chris@101
|
723
|
Chris@101
|
724 // std::cerr << "getYForValue(" << val << "): min " << min << ", max "
|
Chris@101
|
725 // << max << ", log " << logarithmic << std::endl;
|
Chris@101
|
726
|
Chris@101
|
727 if (logarithmic) {
|
Chris@197
|
728 val = LogRange::map(val);
|
Chris@79
|
729 }
|
Chris@79
|
730
|
Chris@66
|
731 return int(h - ((val - min) * h) / (max - min));
|
Chris@21
|
732 }
|
Chris@21
|
733
|
Chris@21
|
734 float
|
Chris@44
|
735 TimeValueLayer::getValueForY(View *v, int y) const
|
Chris@21
|
736 {
|
Chris@101
|
737 float min = 0.0, max = 0.0;
|
Chris@101
|
738 bool logarithmic = false;
|
Chris@44
|
739 int h = v->height();
|
Chris@21
|
740
|
Chris@101
|
741 getScaleExtents(v, min, max, logarithmic);
|
Chris@101
|
742
|
Chris@101
|
743 float val = min + (float(h - y) * float(max - min)) / h;
|
Chris@101
|
744
|
Chris@101
|
745 if (logarithmic) {
|
Chris@437
|
746 val = LogRange::map(val);
|
Chris@101
|
747 }
|
Chris@101
|
748
|
Chris@101
|
749 return val;
|
Chris@21
|
750 }
|
Chris@21
|
751
|
Chris@296
|
752 bool
|
Chris@296
|
753 TimeValueLayer::shouldAutoAlign() const
|
Chris@296
|
754 {
|
Chris@296
|
755 if (!m_model) return false;
|
Chris@296
|
756 QString unit = m_model->getScaleUnits();
|
Chris@296
|
757 return (m_verticalScale == AutoAlignScale && unit != "");
|
Chris@296
|
758 }
|
Chris@296
|
759
|
Chris@68
|
760 QColor
|
Chris@101
|
761 TimeValueLayer::getColourForValue(View *v, float val) const
|
Chris@68
|
762 {
|
Chris@101
|
763 float min, max;
|
Chris@101
|
764 bool log;
|
Chris@101
|
765 getScaleExtents(v, min, max, log);
|
Chris@68
|
766
|
Chris@197
|
767 if (min > max) std::swap(min, max);
|
Chris@197
|
768 if (max == min) max = min + 1;
|
Chris@197
|
769
|
Chris@101
|
770 if (log) {
|
Chris@197
|
771 val = LogRange::map(val);
|
Chris@68
|
772 }
|
Chris@68
|
773
|
Chris@197
|
774 // std::cerr << "TimeValueLayer::getColourForValue: min " << min << ", max "
|
Chris@197
|
775 // << max << ", log " << log << ", value " << val << std::endl;
|
Chris@68
|
776
|
Chris@197
|
777 QColor solid = ColourMapper(m_colourMap, min, max).map(val);
|
Chris@197
|
778 return QColor(solid.red(), solid.green(), solid.blue(), 120);
|
Chris@68
|
779 }
|
Chris@68
|
780
|
Chris@287
|
781 int
|
Chris@287
|
782 TimeValueLayer::getDefaultColourHint(bool darkbg, bool &impose)
|
Chris@287
|
783 {
|
Chris@287
|
784 impose = false;
|
Chris@287
|
785 return ColourDatabase::getInstance()->getColourIndex
|
Chris@287
|
786 (QString(darkbg ? "Bright Green" : "Green"));
|
Chris@287
|
787 }
|
Chris@287
|
788
|
Chris@0
|
789 void
|
Chris@44
|
790 TimeValueLayer::paint(View *v, QPainter &paint, QRect rect) const
|
Chris@0
|
791 {
|
Chris@0
|
792 if (!m_model || !m_model->isOK()) return;
|
Chris@0
|
793
|
Chris@0
|
794 int sampleRate = m_model->getSampleRate();
|
Chris@0
|
795 if (!sampleRate) return;
|
Chris@0
|
796
|
Chris@353
|
797 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@353
|
798
|
Chris@0
|
799 // Profiler profiler("TimeValueLayer::paint", true);
|
Chris@0
|
800
|
Chris@0
|
801 int x0 = rect.left(), x1 = rect.right();
|
Chris@44
|
802 long frame0 = v->getFrameForX(x0);
|
Chris@44
|
803 long frame1 = v->getFrameForX(x1);
|
Chris@0
|
804
|
Chris@0
|
805 SparseTimeValueModel::PointList points(m_model->getPoints
|
Chris@0
|
806 (frame0, frame1));
|
Chris@11
|
807 if (points.empty()) return;
|
Chris@0
|
808
|
Chris@287
|
809 paint.setPen(getBaseQColor());
|
Chris@0
|
810
|
Chris@287
|
811 QColor brushColour(getBaseQColor());
|
Chris@0
|
812 brushColour.setAlpha(80);
|
Chris@0
|
813 paint.setBrush(brushColour);
|
Chris@0
|
814
|
Chris@0
|
815 // std::cerr << "TimeValueLayer::paint: resolution is "
|
Chris@0
|
816 // << m_model->getResolution() << " frames" << std::endl;
|
Chris@0
|
817
|
Chris@0
|
818 float min = m_model->getValueMinimum();
|
Chris@0
|
819 float max = m_model->getValueMaximum();
|
Chris@0
|
820 if (max == min) max = min + 1.0;
|
Chris@0
|
821
|
Chris@44
|
822 int origin = int(nearbyint(v->height() -
|
Chris@44
|
823 (-min * v->height()) / (max - min)));
|
Chris@0
|
824
|
Chris@0
|
825 QPoint localPos;
|
Chris@0
|
826 long illuminateFrame = -1;
|
Chris@0
|
827
|
Chris@44
|
828 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
|
Chris@0
|
829 SparseTimeValueModel::PointList localPoints =
|
Chris@44
|
830 getLocalPoints(v, localPos.x());
|
Chris@296
|
831 // std::cerr << "TimeValueLayer: " << localPoints.size() << " local points" << std::endl;
|
Chris@0
|
832 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
|
Chris@0
|
833 }
|
Chris@6
|
834
|
Chris@20
|
835 int w =
|
Chris@44
|
836 v->getXForFrame(frame0 + m_model->getResolution()) -
|
Chris@44
|
837 v->getXForFrame(frame0);
|
Chris@7
|
838
|
Chris@6
|
839 paint.save();
|
Chris@6
|
840
|
Chris@6
|
841 QPainterPath path;
|
Chris@55
|
842 int pointCount = 0;
|
Chris@79
|
843
|
Chris@79
|
844 int textY = 0;
|
Chris@79
|
845 if (m_plotStyle == PlotSegmentation) {
|
Chris@79
|
846 textY = v->getTextLabelHeight(this, paint);
|
Chris@79
|
847 }
|
Chris@6
|
848
|
Chris@0
|
849 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
|
Chris@0
|
850 i != points.end(); ++i) {
|
Chris@0
|
851
|
Chris@0
|
852 const SparseTimeValueModel::Point &p(*i);
|
Chris@0
|
853
|
Chris@44
|
854 int x = v->getXForFrame(p.frame);
|
Chris@44
|
855 int y = getYForValue(v, p.value);
|
Chris@0
|
856
|
Chris@79
|
857 if (m_plotStyle != PlotSegmentation) {
|
Chris@79
|
858 textY = y - paint.fontMetrics().height()
|
Chris@79
|
859 + paint.fontMetrics().ascent();
|
Chris@372
|
860 if (textY < paint.fontMetrics().ascent() + 1) {
|
Chris@372
|
861 textY = paint.fontMetrics().ascent() + 1;
|
Chris@372
|
862 }
|
Chris@79
|
863 }
|
Chris@79
|
864
|
Chris@34
|
865 bool haveNext = false;
|
Chris@76
|
866 int nx = v->getXForFrame(v->getModelsEndFrame());
|
Chris@34
|
867 int ny = y;
|
Chris@34
|
868
|
Chris@34
|
869 SparseTimeValueModel::PointList::const_iterator j = i;
|
Chris@34
|
870 ++j;
|
Chris@34
|
871
|
Chris@34
|
872 if (j != points.end()) {
|
Chris@34
|
873 const SparseTimeValueModel::Point &q(*j);
|
Chris@44
|
874 nx = v->getXForFrame(q.frame);
|
Chris@44
|
875 ny = getYForValue(v, q.value);
|
Chris@34
|
876 haveNext = true;
|
Chris@76
|
877 }
|
Chris@76
|
878
|
Chris@76
|
879 // std::cout << "frame = " << p.frame << ", x = " << x << ", haveNext = " << haveNext
|
Chris@76
|
880 // << ", nx = " << nx << std::endl;
|
Chris@34
|
881
|
Chris@0
|
882 if (w < 1) w = 1;
|
Chris@287
|
883 paint.setPen(getBaseQColor());
|
Chris@0
|
884
|
Chris@26
|
885 if (m_plotStyle == PlotSegmentation) {
|
Chris@287
|
886 paint.setPen(getForegroundQColor(v));
|
Chris@101
|
887 paint.setBrush(getColourForValue(v, p.value));
|
Chris@26
|
888 } else if (m_plotStyle == PlotLines ||
|
Chris@26
|
889 m_plotStyle == PlotCurve) {
|
Chris@6
|
890 paint.setBrush(Qt::NoBrush);
|
Chris@3
|
891 } else {
|
Chris@6
|
892 paint.setBrush(brushColour);
|
Chris@3
|
893 }
|
Chris@0
|
894
|
Chris@0
|
895 if (m_plotStyle == PlotStems) {
|
Chris@430
|
896 /*
|
Chris@0
|
897 paint.setPen(brushColour);
|
Chris@0
|
898 if (y < origin - 1) {
|
Chris@0
|
899 paint.drawRect(x + w/2, y + 1, 1, origin - y);
|
Chris@0
|
900 } else if (y > origin + 1) {
|
Chris@0
|
901 paint.drawRect(x + w/2, origin, 1, y - origin - 1);
|
Chris@0
|
902 }
|
Chris@430
|
903 */
|
Chris@287
|
904 paint.setPen(getBaseQColor());
|
Chris@430
|
905 if (y < origin - 1) {
|
Chris@430
|
906 paint.drawLine(x + w/2, y + 1, x + w/2, origin);
|
Chris@430
|
907 } else if (y > origin + 1) {
|
Chris@430
|
908 paint.drawLine(x + w/2, origin, x + w/2, y - 1);
|
Chris@430
|
909 }
|
Chris@0
|
910 }
|
Chris@0
|
911
|
Chris@0
|
912 if (illuminateFrame == p.frame) {
|
Chris@6
|
913
|
Chris@0
|
914 //!!! aside from the problem of choosing a colour, it'd be
|
Chris@0
|
915 //better to save the highlighted rects and draw them at
|
Chris@0
|
916 //the end perhaps
|
Chris@6
|
917
|
Chris@6
|
918 //!!! not equipped to illuminate the right section in line
|
Chris@6
|
919 //or curve mode
|
Chris@6
|
920
|
Chris@6
|
921 if (m_plotStyle != PlotCurve &&
|
Chris@6
|
922 m_plotStyle != PlotLines) {
|
Chris@287
|
923 paint.setPen(getForegroundQColor(v));
|
Chris@6
|
924 }
|
Chris@0
|
925 }
|
Chris@0
|
926
|
Chris@6
|
927 if (m_plotStyle != PlotLines &&
|
Chris@26
|
928 m_plotStyle != PlotCurve &&
|
Chris@26
|
929 m_plotStyle != PlotSegmentation) {
|
Chris@326
|
930 if (m_plotStyle != PlotStems ||
|
Chris@326
|
931 w > 1) {
|
Chris@326
|
932 paint.drawRect(x, y - 1, w, 2);
|
Chris@326
|
933 }
|
Chris@3
|
934 }
|
Chris@0
|
935
|
Chris@6
|
936 if (m_plotStyle == PlotConnectedPoints ||
|
Chris@6
|
937 m_plotStyle == PlotLines ||
|
Chris@6
|
938 m_plotStyle == PlotCurve) {
|
Chris@0
|
939
|
Chris@34
|
940 if (haveNext) {
|
Chris@3
|
941
|
Chris@6
|
942 if (m_plotStyle == PlotConnectedPoints) {
|
Chris@34
|
943
|
Chris@79
|
944 paint.save();
|
Chris@3
|
945 paint.setPen(brushColour);
|
Chris@3
|
946 paint.drawLine(x + w, y, nx, ny);
|
Chris@79
|
947 paint.restore();
|
Chris@6
|
948
|
Chris@6
|
949 } else if (m_plotStyle == PlotLines) {
|
Chris@430
|
950
|
Chris@430
|
951 if (pointCount == 0) {
|
Chris@430
|
952 path.moveTo(x + w/2, y);
|
Chris@430
|
953 }
|
Chris@430
|
954 ++pointCount;
|
Chris@6
|
955
|
Chris@430
|
956 // paint.drawLine(x + w/2, y, nx + w/2, ny);
|
Chris@430
|
957 path.lineTo(nx + w/2, ny);
|
Chris@6
|
958
|
Chris@3
|
959 } else {
|
Chris@6
|
960
|
Chris@55
|
961 float x0 = x + float(w)/2;
|
Chris@55
|
962 float x1 = nx + float(w)/2;
|
Chris@55
|
963
|
Chris@55
|
964 float y0 = y;
|
Chris@55
|
965 float y1 = ny;
|
Chris@55
|
966
|
Chris@55
|
967 if (pointCount == 0) {
|
Chris@55
|
968 path.moveTo((x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@6
|
969 }
|
Chris@55
|
970 ++pointCount;
|
Chris@6
|
971
|
Chris@6
|
972 if (nx - x > 5) {
|
Chris@55
|
973 path.cubicTo(x0, y0,
|
Chris@55
|
974 x0, y0,
|
Chris@55
|
975 (x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@55
|
976
|
Chris@55
|
977 // // or
|
Chris@55
|
978 // path.quadTo(x0, y0, (x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@55
|
979
|
Chris@6
|
980 } else {
|
Chris@55
|
981 path.lineTo((x0 + x1) / 2, (y0 + y1) / 2);
|
Chris@6
|
982 }
|
Chris@3
|
983 }
|
Chris@0
|
984 }
|
Chris@0
|
985 }
|
Chris@0
|
986
|
Chris@26
|
987 if (m_plotStyle == PlotSegmentation) {
|
Chris@76
|
988
|
Chris@76
|
989 // std::cerr << "drawing rect" << std::endl;
|
Chris@26
|
990
|
Chris@27
|
991 if (nx <= x) continue;
|
Chris@26
|
992
|
Chris@513
|
993 if (illuminateFrame != p.frame) {
|
Chris@513
|
994 if (!m_drawSegmentDivisions ||
|
Chris@513
|
995 nx < x + 5 ||
|
Chris@513
|
996 x >= v->width() - 1) {
|
Chris@513
|
997 paint.setPen(Qt::NoPen);
|
Chris@513
|
998 }
|
Chris@27
|
999 }
|
Chris@26
|
1000
|
Chris@44
|
1001 paint.drawRect(x, -1, nx - x, v->height() + 1);
|
Chris@26
|
1002 }
|
Chris@26
|
1003
|
Chris@55
|
1004 if (p.label != "") {
|
Chris@79
|
1005 if (!haveNext || nx > x + 6 + paint.fontMetrics().width(p.label)) {
|
Chris@79
|
1006 paint.drawText(x + 5, textY, p.label);
|
Chris@79
|
1007 }
|
Chris@55
|
1008 }
|
Chris@0
|
1009 }
|
Chris@6
|
1010
|
Chris@430
|
1011 if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines)
|
Chris@430
|
1012 && !path.isEmpty()) {
|
Chris@55
|
1013 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width());
|
Chris@6
|
1014 paint.drawPath(path);
|
Chris@6
|
1015 }
|
Chris@6
|
1016
|
Chris@6
|
1017 paint.restore();
|
Chris@6
|
1018
|
Chris@6
|
1019 // looks like save/restore doesn't deal with this:
|
Chris@6
|
1020 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@6
|
1021 }
|
Chris@6
|
1022
|
Chris@42
|
1023 int
|
Chris@248
|
1024 TimeValueLayer::getVerticalScaleWidth(View *, QPainter &paint) const
|
Chris@42
|
1025 {
|
Chris@68
|
1026 int w = paint.fontMetrics().width("-000.000");
|
Chris@68
|
1027 if (m_plotStyle == PlotSegmentation) return w + 20;
|
Chris@68
|
1028 else return w + 10;
|
Chris@42
|
1029 }
|
Chris@42
|
1030
|
Chris@42
|
1031 void
|
Chris@248
|
1032 TimeValueLayer::paintVerticalScale(View *v, QPainter &paint, QRect) const
|
Chris@42
|
1033 {
|
Chris@42
|
1034 if (!m_model) return;
|
Chris@42
|
1035
|
Chris@68
|
1036 int h = v->height();
|
Chris@68
|
1037
|
Chris@68
|
1038 int n = 10;
|
Chris@68
|
1039
|
Chris@437
|
1040 float min, max;
|
Chris@437
|
1041 bool logarithmic;
|
Chris@437
|
1042 getScaleExtents(v, min, max, logarithmic);
|
Chris@437
|
1043
|
Chris@437
|
1044 if (m_plotStyle == PlotSegmentation) {
|
Chris@437
|
1045 QString unit;
|
Chris@437
|
1046 getValueExtents(min, max, logarithmic, unit);
|
Chris@437
|
1047 if (logarithmic) {
|
Chris@437
|
1048 LogRange::mapRange(min, max);
|
Chris@437
|
1049 }
|
Chris@437
|
1050 }
|
Chris@437
|
1051
|
Chris@68
|
1052 float val = min;
|
Chris@68
|
1053 float inc = (max - val) / n;
|
Chris@42
|
1054
|
Chris@55
|
1055 char buffer[40];
|
Chris@55
|
1056
|
Chris@55
|
1057 int w = getVerticalScaleWidth(v, paint);
|
Chris@55
|
1058
|
Chris@68
|
1059 int tx = 5;
|
Chris@68
|
1060
|
Chris@68
|
1061 int boxx = 5, boxy = 5;
|
Chris@68
|
1062 if (m_model->getScaleUnits() != "") {
|
Chris@68
|
1063 boxy += paint.fontMetrics().height();
|
Chris@68
|
1064 }
|
Chris@68
|
1065 int boxw = 10, boxh = h - boxy - 5;
|
Chris@68
|
1066
|
Chris@68
|
1067 if (m_plotStyle == PlotSegmentation) {
|
Chris@68
|
1068 tx += boxx + boxw;
|
Chris@68
|
1069 paint.drawRect(boxx, boxy, boxw, boxh);
|
Chris@68
|
1070 }
|
Chris@68
|
1071
|
Chris@68
|
1072 if (m_plotStyle == PlotSegmentation) {
|
Chris@68
|
1073 paint.save();
|
Chris@68
|
1074 for (int y = 0; y < boxh; ++y) {
|
Chris@68
|
1075 float val = ((boxh - y) * (max - min)) / boxh + min;
|
Chris@437
|
1076 if (logarithmic) {
|
Chris@437
|
1077 paint.setPen(getColourForValue(v, LogRange::unmap(val)));
|
Chris@437
|
1078 } else {
|
Chris@437
|
1079 paint.setPen(getColourForValue(v, val));
|
Chris@437
|
1080 }
|
Chris@68
|
1081 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1);
|
Chris@68
|
1082 }
|
Chris@68
|
1083 paint.restore();
|
Chris@68
|
1084 }
|
Chris@434
|
1085
|
Chris@434
|
1086 float round = 1.f;
|
Chris@434
|
1087 int dp = 0;
|
Chris@434
|
1088 if (inc > 0) {
|
Chris@434
|
1089 int prec = trunc(log10f(inc));
|
Chris@434
|
1090 prec -= 1;
|
Chris@434
|
1091 if (prec < 0) dp = -prec;
|
Chris@434
|
1092 round = powf(10.f, prec);
|
Chris@434
|
1093 // std::cerr << "inc = " << inc << ", round = " << round << std::endl;
|
Chris@434
|
1094 }
|
Chris@68
|
1095
|
Chris@434
|
1096 int prevy = -1;
|
Chris@434
|
1097
|
Chris@68
|
1098 for (int i = 0; i < n; ++i) {
|
Chris@68
|
1099
|
Chris@68
|
1100 int y, ty;
|
Chris@68
|
1101 bool drawText = true;
|
Chris@68
|
1102
|
Chris@434
|
1103 float dispval = val;
|
Chris@434
|
1104
|
Chris@68
|
1105 if (m_plotStyle == PlotSegmentation) {
|
Chris@68
|
1106 y = boxy + int(boxh - ((val - min) * boxh) / (max - min));
|
Chris@68
|
1107 ty = y;
|
Chris@68
|
1108 } else {
|
Chris@437
|
1109 if (i == n-1 &&
|
Chris@437
|
1110 v->height() < paint.fontMetrics().height() * (n*2)) {
|
Chris@68
|
1111 if (m_model->getScaleUnits() != "") drawText = false;
|
Chris@68
|
1112 }
|
Chris@434
|
1113 dispval = lrintf(val / round) * round;
|
Chris@434
|
1114 // std::cerr << "val = " << val << ", dispval = " << dispval << std::endl;
|
Chris@437
|
1115 if (logarithmic) {
|
Chris@437
|
1116 y = getYForValue(v, LogRange::unmap(dispval));
|
Chris@437
|
1117 } else {
|
Chris@437
|
1118 y = getYForValue(v, dispval);
|
Chris@437
|
1119 }
|
Chris@68
|
1120 ty = y - paint.fontMetrics().height() +
|
Chris@434
|
1121 paint.fontMetrics().ascent() + 2;
|
Chris@434
|
1122
|
Chris@434
|
1123 if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) {
|
Chris@434
|
1124 val += inc;
|
Chris@434
|
1125 continue;
|
Chris@434
|
1126 }
|
Chris@68
|
1127 }
|
Chris@68
|
1128
|
Chris@437
|
1129 if (logarithmic) {
|
Chris@437
|
1130 sprintf(buffer, "%.*g", dp < 2 ? 2 : dp, LogRange::unmap(dispval));
|
Chris@437
|
1131 } else {
|
Chris@437
|
1132 sprintf(buffer, "%.*f", dp, dispval);
|
Chris@437
|
1133 }
|
Chris@55
|
1134 QString label = QString(buffer);
|
Chris@68
|
1135
|
Chris@68
|
1136 if (m_plotStyle != PlotSegmentation) {
|
Chris@68
|
1137 paint.drawLine(w - 5, y, w, y);
|
Chris@68
|
1138 } else {
|
Chris@68
|
1139 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y);
|
Chris@68
|
1140 }
|
Chris@68
|
1141
|
Chris@434
|
1142 if (drawText) {
|
Chris@435
|
1143 if (m_plotStyle != PlotSegmentation) {
|
Chris@435
|
1144 paint.drawText(tx + w - paint.fontMetrics().width(label) - 8,
|
Chris@435
|
1145 ty, label);
|
Chris@435
|
1146 } else {
|
Chris@435
|
1147 paint.drawText(tx, ty, label);
|
Chris@435
|
1148 }
|
Chris@434
|
1149 }
|
Chris@434
|
1150
|
Chris@434
|
1151 prevy = y;
|
Chris@44
|
1152 val += inc;
|
Chris@42
|
1153 }
|
Chris@68
|
1154
|
Chris@67
|
1155 if (m_model->getScaleUnits() != "") {
|
Chris@67
|
1156 paint.drawText(5, 5 + paint.fontMetrics().ascent(),
|
Chris@67
|
1157 m_model->getScaleUnits());
|
Chris@67
|
1158 }
|
Chris@42
|
1159 }
|
Chris@42
|
1160
|
Chris@21
|
1161 void
|
Chris@44
|
1162 TimeValueLayer::drawStart(View *v, QMouseEvent *e)
|
Chris@21
|
1163 {
|
Chris@101
|
1164 // std::cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
1165
|
Chris@21
|
1166 if (!m_model) return;
|
Chris@21
|
1167
|
Chris@44
|
1168 long frame = v->getFrameForX(e->x());
|
Chris@76
|
1169 long resolution = m_model->getResolution();
|
Chris@21
|
1170 if (frame < 0) frame = 0;
|
Chris@76
|
1171 frame = (frame / resolution) * resolution;
|
Chris@21
|
1172
|
Chris@44
|
1173 float value = getValueForY(v, e->y());
|
Chris@21
|
1174
|
Chris@76
|
1175 bool havePoint = false;
|
Chris@76
|
1176
|
Chris@76
|
1177 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@76
|
1178 if (!points.empty()) {
|
Chris@76
|
1179 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1180 i != points.end(); ++i) {
|
Chris@76
|
1181 if (((i->frame / resolution) * resolution) != frame) {
|
Chris@101
|
1182 // std::cerr << "ignoring out-of-range frame at " << i->frame << std::endl;
|
Chris@76
|
1183 continue;
|
Chris@76
|
1184 }
|
Chris@76
|
1185 m_editingPoint = *i;
|
Chris@76
|
1186 havePoint = true;
|
Chris@76
|
1187 }
|
Chris@76
|
1188 }
|
Chris@76
|
1189
|
Chris@76
|
1190 if (!havePoint) {
|
Chris@76
|
1191 m_editingPoint = SparseTimeValueModel::Point
|
Chris@76
|
1192 (frame, value, tr("New Point"));
|
Chris@76
|
1193 }
|
Chris@76
|
1194
|
Chris@23
|
1195 m_originalPoint = m_editingPoint;
|
Chris@22
|
1196
|
Chris@376
|
1197 if (m_editingCommand) finish(m_editingCommand);
|
Chris@22
|
1198 m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
|
Chris@22
|
1199 tr("Draw Point"));
|
Chris@76
|
1200 if (!havePoint) {
|
Chris@76
|
1201 m_editingCommand->addPoint(m_editingPoint);
|
Chris@76
|
1202 }
|
Chris@22
|
1203
|
Chris@21
|
1204 m_editing = true;
|
Chris@21
|
1205 }
|
Chris@21
|
1206
|
Chris@21
|
1207 void
|
Chris@44
|
1208 TimeValueLayer::drawDrag(View *v, QMouseEvent *e)
|
Chris@21
|
1209 {
|
Chris@101
|
1210 // std::cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
1211
|
Chris@21
|
1212 if (!m_model || !m_editing) return;
|
Chris@21
|
1213
|
Chris@44
|
1214 long frame = v->getFrameForX(e->x());
|
Chris@76
|
1215 long resolution = m_model->getResolution();
|
Chris@21
|
1216 if (frame < 0) frame = 0;
|
Chris@76
|
1217 frame = (frame / resolution) * resolution;
|
Chris@21
|
1218
|
Chris@44
|
1219 float value = getValueForY(v, e->y());
|
Chris@21
|
1220
|
Chris@76
|
1221 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@76
|
1222
|
Chris@101
|
1223 // std::cerr << points.size() << " points" << std::endl;
|
Chris@76
|
1224
|
Chris@76
|
1225 bool havePoint = false;
|
Chris@76
|
1226
|
Chris@76
|
1227 if (!points.empty()) {
|
Chris@76
|
1228 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1229 i != points.end(); ++i) {
|
Chris@76
|
1230 if (i->frame == m_editingPoint.frame &&
|
Chris@76
|
1231 i->value == m_editingPoint.value) {
|
Chris@101
|
1232 // std::cerr << "ignoring current editing point at " << i->frame << ", " << i->value << std::endl;
|
Chris@76
|
1233 continue;
|
Chris@76
|
1234 }
|
Chris@76
|
1235 if (((i->frame / resolution) * resolution) != frame) {
|
Chris@101
|
1236 // std::cerr << "ignoring out-of-range frame at " << i->frame << std::endl;
|
Chris@76
|
1237 continue;
|
Chris@76
|
1238 }
|
Chris@101
|
1239 // std::cerr << "adjusting to new point at " << i->frame << ", " << i->value << std::endl;
|
Chris@76
|
1240 m_editingPoint = *i;
|
Chris@76
|
1241 m_originalPoint = m_editingPoint;
|
Chris@76
|
1242 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@76
|
1243 havePoint = true;
|
Chris@76
|
1244 }
|
Chris@76
|
1245 }
|
Chris@76
|
1246
|
Chris@76
|
1247 if (!havePoint) {
|
Chris@76
|
1248 if (frame == m_editingPoint.frame) {
|
Chris@76
|
1249 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@76
|
1250 }
|
Chris@76
|
1251 }
|
Chris@76
|
1252
|
Chris@76
|
1253 // m_editingCommand->deletePoint(m_editingPoint);
|
Chris@21
|
1254 m_editingPoint.frame = frame;
|
Chris@21
|
1255 m_editingPoint.value = value;
|
Chris@22
|
1256 m_editingCommand->addPoint(m_editingPoint);
|
Chris@21
|
1257 }
|
Chris@21
|
1258
|
Chris@21
|
1259 void
|
Chris@248
|
1260 TimeValueLayer::drawEnd(View *, QMouseEvent *)
|
Chris@21
|
1261 {
|
Chris@101
|
1262 // std::cerr << "TimeValueLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
1263 if (!m_model || !m_editing) return;
|
Chris@376
|
1264 finish(m_editingCommand);
|
Chris@22
|
1265 m_editingCommand = 0;
|
Chris@21
|
1266 m_editing = false;
|
Chris@21
|
1267 }
|
Chris@21
|
1268
|
Chris@21
|
1269 void
|
Chris@335
|
1270 TimeValueLayer::eraseStart(View *v, QMouseEvent *e)
|
Chris@335
|
1271 {
|
Chris@335
|
1272 if (!m_model) return;
|
Chris@335
|
1273
|
Chris@335
|
1274 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@335
|
1275 if (points.empty()) return;
|
Chris@335
|
1276
|
Chris@335
|
1277 m_editingPoint = *points.begin();
|
Chris@335
|
1278
|
Chris@335
|
1279 if (m_editingCommand) {
|
Chris@376
|
1280 finish(m_editingCommand);
|
Chris@335
|
1281 m_editingCommand = 0;
|
Chris@335
|
1282 }
|
Chris@335
|
1283
|
Chris@335
|
1284 m_editing = true;
|
Chris@335
|
1285 }
|
Chris@335
|
1286
|
Chris@335
|
1287 void
|
Chris@335
|
1288 TimeValueLayer::eraseDrag(View *v, QMouseEvent *e)
|
Chris@335
|
1289 {
|
Chris@335
|
1290 }
|
Chris@335
|
1291
|
Chris@335
|
1292 void
|
Chris@335
|
1293 TimeValueLayer::eraseEnd(View *v, QMouseEvent *e)
|
Chris@335
|
1294 {
|
Chris@335
|
1295 if (!m_model || !m_editing) return;
|
Chris@335
|
1296
|
Chris@335
|
1297 m_editing = false;
|
Chris@335
|
1298
|
Chris@335
|
1299 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@335
|
1300 if (points.empty()) return;
|
Chris@335
|
1301 if (points.begin()->frame != m_editingPoint.frame ||
|
Chris@335
|
1302 points.begin()->value != m_editingPoint.value) return;
|
Chris@335
|
1303
|
Chris@335
|
1304 m_editingCommand = new SparseTimeValueModel::EditCommand
|
Chris@335
|
1305 (m_model, tr("Erase Point"));
|
Chris@335
|
1306
|
Chris@335
|
1307 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@335
|
1308
|
Chris@376
|
1309 finish(m_editingCommand);
|
Chris@335
|
1310 m_editingCommand = 0;
|
Chris@335
|
1311 m_editing = false;
|
Chris@335
|
1312 }
|
Chris@335
|
1313
|
Chris@335
|
1314 void
|
Chris@44
|
1315 TimeValueLayer::editStart(View *v, QMouseEvent *e)
|
Chris@21
|
1316 {
|
Chris@101
|
1317 // std::cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
1318
|
Chris@21
|
1319 if (!m_model) return;
|
Chris@21
|
1320
|
Chris@44
|
1321 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@21
|
1322 if (points.empty()) return;
|
Chris@21
|
1323
|
Chris@21
|
1324 m_editingPoint = *points.begin();
|
Chris@23
|
1325 m_originalPoint = m_editingPoint;
|
Chris@22
|
1326
|
Chris@22
|
1327 if (m_editingCommand) {
|
Chris@376
|
1328 finish(m_editingCommand);
|
Chris@22
|
1329 m_editingCommand = 0;
|
Chris@22
|
1330 }
|
Chris@22
|
1331
|
Chris@21
|
1332 m_editing = true;
|
Chris@21
|
1333 }
|
Chris@21
|
1334
|
Chris@21
|
1335 void
|
Chris@44
|
1336 TimeValueLayer::editDrag(View *v, QMouseEvent *e)
|
Chris@21
|
1337 {
|
Chris@101
|
1338 // std::cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
1339
|
Chris@21
|
1340 if (!m_model || !m_editing) return;
|
Chris@21
|
1341
|
Chris@44
|
1342 long frame = v->getFrameForX(e->x());
|
Chris@21
|
1343 if (frame < 0) frame = 0;
|
Chris@21
|
1344 frame = frame / m_model->getResolution() * m_model->getResolution();
|
Chris@21
|
1345
|
Chris@44
|
1346 float value = getValueForY(v, e->y());
|
Chris@21
|
1347
|
Chris@22
|
1348 if (!m_editingCommand) {
|
Chris@22
|
1349 m_editingCommand = new SparseTimeValueModel::EditCommand(m_model,
|
Chris@22
|
1350 tr("Drag Point"));
|
Chris@22
|
1351 }
|
Chris@22
|
1352
|
Chris@22
|
1353 m_editingCommand->deletePoint(m_editingPoint);
|
Chris@21
|
1354 m_editingPoint.frame = frame;
|
Chris@21
|
1355 m_editingPoint.value = value;
|
Chris@22
|
1356 m_editingCommand->addPoint(m_editingPoint);
|
Chris@21
|
1357 }
|
Chris@21
|
1358
|
Chris@21
|
1359 void
|
Chris@248
|
1360 TimeValueLayer::editEnd(View *, QMouseEvent *)
|
Chris@21
|
1361 {
|
Chris@101
|
1362 // std::cerr << "TimeValueLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl;
|
Chris@21
|
1363 if (!m_model || !m_editing) return;
|
Chris@23
|
1364
|
Chris@23
|
1365 if (m_editingCommand) {
|
Chris@23
|
1366
|
Chris@23
|
1367 QString newName = m_editingCommand->getName();
|
Chris@23
|
1368
|
Chris@23
|
1369 if (m_editingPoint.frame != m_originalPoint.frame) {
|
Chris@23
|
1370 if (m_editingPoint.value != m_originalPoint.value) {
|
Chris@23
|
1371 newName = tr("Edit Point");
|
Chris@23
|
1372 } else {
|
Chris@23
|
1373 newName = tr("Relocate Point");
|
Chris@23
|
1374 }
|
Chris@23
|
1375 } else {
|
Chris@23
|
1376 newName = tr("Change Point Value");
|
Chris@23
|
1377 }
|
Chris@23
|
1378
|
Chris@23
|
1379 m_editingCommand->setName(newName);
|
Chris@376
|
1380 finish(m_editingCommand);
|
Chris@23
|
1381 }
|
Chris@23
|
1382
|
Chris@22
|
1383 m_editingCommand = 0;
|
Chris@21
|
1384 m_editing = false;
|
Chris@21
|
1385 }
|
Chris@21
|
1386
|
Chris@255
|
1387 bool
|
Chris@70
|
1388 TimeValueLayer::editOpen(View *v, QMouseEvent *e)
|
Chris@70
|
1389 {
|
Chris@255
|
1390 if (!m_model) return false;
|
Chris@70
|
1391
|
Chris@70
|
1392 SparseTimeValueModel::PointList points = getLocalPoints(v, e->x());
|
Chris@255
|
1393 if (points.empty()) return false;
|
Chris@70
|
1394
|
Chris@70
|
1395 SparseTimeValueModel::Point point = *points.begin();
|
Chris@70
|
1396
|
Chris@70
|
1397 ItemEditDialog *dialog = new ItemEditDialog
|
Chris@70
|
1398 (m_model->getSampleRate(),
|
Chris@70
|
1399 ItemEditDialog::ShowTime |
|
Chris@70
|
1400 ItemEditDialog::ShowValue |
|
Chris@73
|
1401 ItemEditDialog::ShowText,
|
Chris@73
|
1402 m_model->getScaleUnits());
|
Chris@70
|
1403
|
Chris@70
|
1404 dialog->setFrameTime(point.frame);
|
Chris@70
|
1405 dialog->setValue(point.value);
|
Chris@70
|
1406 dialog->setText(point.label);
|
Chris@70
|
1407
|
Chris@70
|
1408 if (dialog->exec() == QDialog::Accepted) {
|
Chris@70
|
1409
|
Chris@70
|
1410 SparseTimeValueModel::Point newPoint = point;
|
Chris@70
|
1411 newPoint.frame = dialog->getFrameTime();
|
Chris@70
|
1412 newPoint.value = dialog->getValue();
|
Chris@70
|
1413 newPoint.label = dialog->getText();
|
Chris@70
|
1414
|
Chris@70
|
1415 SparseTimeValueModel::EditCommand *command =
|
Chris@70
|
1416 new SparseTimeValueModel::EditCommand(m_model, tr("Edit Point"));
|
Chris@70
|
1417 command->deletePoint(point);
|
Chris@70
|
1418 command->addPoint(newPoint);
|
Chris@376
|
1419 finish(command);
|
Chris@70
|
1420 }
|
Chris@70
|
1421
|
Chris@70
|
1422 delete dialog;
|
Chris@255
|
1423 return true;
|
Chris@70
|
1424 }
|
Chris@70
|
1425
|
Chris@70
|
1426 void
|
Chris@43
|
1427 TimeValueLayer::moveSelection(Selection s, size_t newStartFrame)
|
Chris@43
|
1428 {
|
Chris@99
|
1429 if (!m_model) return;
|
Chris@99
|
1430
|
Chris@43
|
1431 SparseTimeValueModel::EditCommand *command =
|
Chris@43
|
1432 new SparseTimeValueModel::EditCommand(m_model,
|
Chris@43
|
1433 tr("Drag Selection"));
|
Chris@43
|
1434
|
Chris@43
|
1435 SparseTimeValueModel::PointList points =
|
Chris@43
|
1436 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@43
|
1437
|
Chris@43
|
1438 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@43
|
1439 i != points.end(); ++i) {
|
Chris@43
|
1440
|
Chris@43
|
1441 if (s.contains(i->frame)) {
|
Chris@43
|
1442 SparseTimeValueModel::Point newPoint(*i);
|
Chris@43
|
1443 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
|
Chris@43
|
1444 command->deletePoint(*i);
|
Chris@43
|
1445 command->addPoint(newPoint);
|
Chris@43
|
1446 }
|
Chris@43
|
1447 }
|
Chris@43
|
1448
|
Chris@376
|
1449 finish(command);
|
Chris@43
|
1450 }
|
Chris@43
|
1451
|
Chris@43
|
1452 void
|
Chris@43
|
1453 TimeValueLayer::resizeSelection(Selection s, Selection newSize)
|
Chris@43
|
1454 {
|
Chris@99
|
1455 if (!m_model) return;
|
Chris@99
|
1456
|
Chris@43
|
1457 SparseTimeValueModel::EditCommand *command =
|
Chris@43
|
1458 new SparseTimeValueModel::EditCommand(m_model,
|
Chris@43
|
1459 tr("Resize Selection"));
|
Chris@43
|
1460
|
Chris@43
|
1461 SparseTimeValueModel::PointList points =
|
Chris@43
|
1462 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@43
|
1463
|
Chris@43
|
1464 double ratio =
|
Chris@43
|
1465 double(newSize.getEndFrame() - newSize.getStartFrame()) /
|
Chris@43
|
1466 double(s.getEndFrame() - s.getStartFrame());
|
Chris@43
|
1467
|
Chris@43
|
1468 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@43
|
1469 i != points.end(); ++i) {
|
Chris@43
|
1470
|
Chris@43
|
1471 if (s.contains(i->frame)) {
|
Chris@43
|
1472
|
Chris@43
|
1473 double target = i->frame;
|
Chris@43
|
1474 target = newSize.getStartFrame() +
|
Chris@43
|
1475 double(target - s.getStartFrame()) * ratio;
|
Chris@43
|
1476
|
Chris@43
|
1477 SparseTimeValueModel::Point newPoint(*i);
|
Chris@43
|
1478 newPoint.frame = lrint(target);
|
Chris@43
|
1479 command->deletePoint(*i);
|
Chris@43
|
1480 command->addPoint(newPoint);
|
Chris@43
|
1481 }
|
Chris@43
|
1482 }
|
Chris@43
|
1483
|
Chris@376
|
1484 finish(command);
|
Chris@43
|
1485 }
|
Chris@43
|
1486
|
Chris@76
|
1487 void
|
Chris@76
|
1488 TimeValueLayer::deleteSelection(Selection s)
|
Chris@76
|
1489 {
|
Chris@99
|
1490 if (!m_model) return;
|
Chris@99
|
1491
|
Chris@76
|
1492 SparseTimeValueModel::EditCommand *command =
|
Chris@76
|
1493 new SparseTimeValueModel::EditCommand(m_model,
|
Chris@76
|
1494 tr("Delete Selected Points"));
|
Chris@76
|
1495
|
Chris@76
|
1496 SparseTimeValueModel::PointList points =
|
Chris@76
|
1497 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@76
|
1498
|
Chris@76
|
1499 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1500 i != points.end(); ++i) {
|
Chris@76
|
1501
|
Chris@76
|
1502 if (s.contains(i->frame)) {
|
Chris@76
|
1503 command->deletePoint(*i);
|
Chris@76
|
1504 }
|
Chris@76
|
1505 }
|
Chris@76
|
1506
|
Chris@376
|
1507 finish(command);
|
Chris@76
|
1508 }
|
Chris@76
|
1509
|
Chris@76
|
1510 void
|
Chris@359
|
1511 TimeValueLayer::copy(View *v, Selection s, Clipboard &to)
|
Chris@76
|
1512 {
|
Chris@99
|
1513 if (!m_model) return;
|
Chris@99
|
1514
|
Chris@76
|
1515 SparseTimeValueModel::PointList points =
|
Chris@76
|
1516 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
|
Chris@76
|
1517
|
Chris@76
|
1518 for (SparseTimeValueModel::PointList::iterator i = points.begin();
|
Chris@76
|
1519 i != points.end(); ++i) {
|
Chris@76
|
1520 if (s.contains(i->frame)) {
|
Chris@83
|
1521 Clipboard::Point point(i->frame, i->value, i->label);
|
Chris@360
|
1522 point.setReferenceFrame(alignToReference(v, i->frame));
|
Chris@76
|
1523 to.addPoint(point);
|
Chris@76
|
1524 }
|
Chris@76
|
1525 }
|
Chris@76
|
1526 }
|
Chris@76
|
1527
|
Chris@125
|
1528 bool
|
Chris@359
|
1529 TimeValueLayer::paste(View *v, const Clipboard &from, int frameOffset,
|
Chris@125
|
1530 bool interactive)
|
Chris@76
|
1531 {
|
Chris@125
|
1532 if (!m_model) return false;
|
Chris@99
|
1533
|
Chris@76
|
1534 const Clipboard::PointList &points = from.getPoints();
|
Chris@76
|
1535
|
Chris@360
|
1536 bool realign = false;
|
Chris@360
|
1537
|
Chris@360
|
1538 if (clipboardHasDifferentAlignment(v, from)) {
|
Chris@360
|
1539
|
Chris@360
|
1540 QMessageBox::StandardButton button =
|
Chris@360
|
1541 QMessageBox::question(v, tr("Re-align pasted items?"),
|
Chris@360
|
1542 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
|
Chris@360
|
1543 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
Chris@360
|
1544 QMessageBox::Yes);
|
Chris@360
|
1545
|
Chris@360
|
1546 if (button == QMessageBox::Cancel) {
|
Chris@360
|
1547 return false;
|
Chris@360
|
1548 }
|
Chris@360
|
1549
|
Chris@360
|
1550 if (button == QMessageBox::Yes) {
|
Chris@360
|
1551 realign = true;
|
Chris@360
|
1552 }
|
Chris@360
|
1553 }
|
Chris@360
|
1554
|
Chris@76
|
1555 SparseTimeValueModel::EditCommand *command =
|
Chris@76
|
1556 new SparseTimeValueModel::EditCommand(m_model, tr("Paste"));
|
Chris@76
|
1557
|
Chris@125
|
1558 enum ValueAvailability {
|
Chris@125
|
1559 UnknownAvailability,
|
Chris@125
|
1560 NoValues,
|
Chris@125
|
1561 SomeValues,
|
Chris@125
|
1562 AllValues
|
Chris@125
|
1563 };
|
Chris@125
|
1564
|
Chris@340
|
1565 Labeller::ValueType generation = Labeller::ValueNone;
|
Chris@125
|
1566
|
Chris@125
|
1567 bool haveUsableLabels = false;
|
Chris@125
|
1568 bool haveExistingItems = !(m_model->isEmpty());
|
Chris@340
|
1569 Labeller labeller;
|
Chris@340
|
1570 labeller.setSampleRate(m_model->getSampleRate());
|
Chris@125
|
1571
|
Chris@125
|
1572 if (interactive) {
|
Chris@125
|
1573
|
Chris@125
|
1574 ValueAvailability availability = UnknownAvailability;
|
Chris@125
|
1575
|
Chris@125
|
1576 for (Clipboard::PointList::const_iterator i = points.begin();
|
Chris@125
|
1577 i != points.end(); ++i) {
|
Chris@125
|
1578
|
Chris@125
|
1579 if (!i->haveFrame()) continue;
|
Chris@125
|
1580
|
Chris@125
|
1581 if (availability == UnknownAvailability) {
|
Chris@125
|
1582 if (i->haveValue()) availability = AllValues;
|
Chris@125
|
1583 else availability = NoValues;
|
Chris@125
|
1584 continue;
|
Chris@125
|
1585 }
|
Chris@125
|
1586
|
Chris@125
|
1587 if (i->haveValue()) {
|
Chris@125
|
1588 if (availability == NoValues) {
|
Chris@125
|
1589 availability = SomeValues;
|
Chris@125
|
1590 }
|
Chris@125
|
1591 } else {
|
Chris@125
|
1592 if (availability == AllValues) {
|
Chris@125
|
1593 availability = SomeValues;
|
Chris@125
|
1594 }
|
Chris@125
|
1595 }
|
Chris@125
|
1596
|
Chris@125
|
1597 if (!haveUsableLabels) {
|
Chris@125
|
1598 if (i->haveLabel()) {
|
Chris@125
|
1599 if (i->getLabel().contains(QRegExp("[0-9]"))) {
|
Chris@125
|
1600 haveUsableLabels = true;
|
Chris@125
|
1601 }
|
Chris@125
|
1602 }
|
Chris@125
|
1603 }
|
Chris@125
|
1604
|
Chris@125
|
1605 if (availability == SomeValues && haveUsableLabels) break;
|
Chris@125
|
1606 }
|
Chris@125
|
1607
|
Chris@125
|
1608 if (availability == NoValues || availability == SomeValues) {
|
Chris@125
|
1609
|
Chris@125
|
1610 QString text;
|
Chris@125
|
1611 if (availability == NoValues) {
|
Chris@125
|
1612 text = tr("The items you are pasting do not have values.\nWhat values do you want to use for these items?");
|
Chris@125
|
1613 } else {
|
Chris@125
|
1614 text = tr("Some of the items you are pasting do not have values.\nWhat values do you want to use for these items?");
|
Chris@125
|
1615 }
|
Chris@125
|
1616
|
Chris@340
|
1617 Labeller::TypeNameMap names = labeller.getTypeNames();
|
Chris@340
|
1618
|
Chris@125
|
1619 QStringList options;
|
Chris@340
|
1620 std::vector<Labeller::ValueType> genopts;
|
Chris@125
|
1621
|
Chris@340
|
1622 for (Labeller::TypeNameMap::const_iterator i = names.begin();
|
Chris@340
|
1623 i != names.end(); ++i) {
|
Chris@340
|
1624 if (i->first == Labeller::ValueNone) options << tr("Zero for all items");
|
Chris@340
|
1625 else options << i->second;
|
Chris@340
|
1626 genopts.push_back(i->first);
|
Chris@125
|
1627 }
|
Chris@125
|
1628
|
Chris@125
|
1629 static int prevSelection = 0;
|
Chris@125
|
1630
|
Chris@125
|
1631 bool ok = false;
|
Chris@125
|
1632 QString selected = ListInputDialog::getItem
|
Chris@125
|
1633 (0, tr("Choose value calculation"),
|
Chris@125
|
1634 text, options, prevSelection, &ok);
|
Chris@125
|
1635
|
Chris@125
|
1636 if (!ok) return false;
|
Chris@125
|
1637 int selection = 0;
|
Chris@340
|
1638 generation = Labeller::ValueNone;
|
Chris@125
|
1639
|
Chris@125
|
1640 for (QStringList::const_iterator i = options.begin();
|
Chris@125
|
1641 i != options.end(); ++i) {
|
Chris@125
|
1642 if (selected == *i) {
|
Chris@340
|
1643 generation = genopts[selection];
|
Chris@125
|
1644 break;
|
Chris@125
|
1645 }
|
Chris@125
|
1646 ++selection;
|
Chris@125
|
1647 }
|
Chris@340
|
1648
|
Chris@340
|
1649 labeller.setType(generation);
|
Chris@340
|
1650
|
Chris@340
|
1651 if (generation == Labeller::ValueFromCyclicalCounter ||
|
Chris@340
|
1652 generation == Labeller::ValueFromTwoLevelCounter) {
|
Chris@340
|
1653 int cycleSize = QInputDialog::getInteger
|
Chris@340
|
1654 (0, tr("Select cycle size"),
|
Chris@340
|
1655 tr("Cycle size:"), 4, 2, 16, 1);
|
Chris@340
|
1656 labeller.setCounterCycleSize(cycleSize);
|
Chris@340
|
1657 }
|
Chris@125
|
1658
|
Chris@125
|
1659 prevSelection = selection;
|
Chris@125
|
1660 }
|
Chris@125
|
1661 }
|
Chris@125
|
1662
|
Chris@372
|
1663 SparseTimeValueModel::Point prevPoint(0);
|
Chris@125
|
1664
|
Chris@76
|
1665 for (Clipboard::PointList::const_iterator i = points.begin();
|
Chris@76
|
1666 i != points.end(); ++i) {
|
Chris@76
|
1667
|
Chris@76
|
1668 if (!i->haveFrame()) continue;
|
Chris@360
|
1669
|
Chris@76
|
1670 size_t frame = 0;
|
Chris@360
|
1671
|
Chris@360
|
1672 if (!realign) {
|
Chris@360
|
1673
|
Chris@360
|
1674 frame = i->getFrame();
|
Chris@360
|
1675
|
Chris@360
|
1676 } else {
|
Chris@360
|
1677
|
Chris@360
|
1678 if (i->haveReferenceFrame()) {
|
Chris@360
|
1679 frame = i->getReferenceFrame();
|
Chris@360
|
1680 frame = alignFromReference(v, frame);
|
Chris@360
|
1681 } else {
|
Chris@360
|
1682 frame = i->getFrame();
|
Chris@360
|
1683 }
|
Chris@76
|
1684 }
|
Chris@360
|
1685
|
Chris@76
|
1686 SparseTimeValueModel::Point newPoint(frame);
|
Chris@76
|
1687
|
Chris@125
|
1688 if (i->haveLabel()) {
|
Chris@125
|
1689 newPoint.label = i->getLabel();
|
Chris@125
|
1690 } else if (i->haveValue()) {
|
Chris@125
|
1691 newPoint.label = QString("%1").arg(i->getValue());
|
Chris@125
|
1692 }
|
Chris@125
|
1693
|
Chris@372
|
1694 bool usePrev = false;
|
Chris@372
|
1695 SparseTimeValueModel::Point formerPrevPoint = prevPoint;
|
Chris@372
|
1696
|
Chris@125
|
1697 if (i->haveValue()) {
|
Chris@125
|
1698 newPoint.value = i->getValue();
|
Chris@125
|
1699 } else {
|
Chris@372
|
1700 // std::cerr << "Setting value on point at " << newPoint.frame << " from labeller";
|
Chris@372
|
1701 // if (i == points.begin()) {
|
Chris@372
|
1702 // std::cerr << ", no prev point" << std::endl;
|
Chris@372
|
1703 // } else {
|
Chris@372
|
1704 // std::cerr << ", prev point is at " << prevPoint.frame << std::endl;
|
Chris@372
|
1705 // }
|
Chris@340
|
1706 labeller.setValue<SparseTimeValueModel::Point>
|
Chris@371
|
1707 (newPoint, (i == points.begin()) ? 0 : &prevPoint);
|
Chris@372
|
1708 // std::cerr << "New point value = " << newPoint.value << std::endl;
|
Chris@372
|
1709 if (labeller.actingOnPrevPoint() && i != points.begin()) {
|
Chris@372
|
1710 usePrev = true;
|
Chris@372
|
1711 }
|
Chris@372
|
1712 }
|
Chris@372
|
1713
|
Chris@372
|
1714 if (usePrev) {
|
Chris@372
|
1715 command->deletePoint(formerPrevPoint);
|
Chris@372
|
1716 command->addPoint(prevPoint);
|
Chris@340
|
1717 }
|
Chris@125
|
1718
|
Chris@340
|
1719 prevPoint = newPoint;
|
Chris@76
|
1720 command->addPoint(newPoint);
|
Chris@76
|
1721 }
|
Chris@76
|
1722
|
Chris@376
|
1723 finish(command);
|
Chris@125
|
1724 return true;
|
Chris@360
|
1725 }
|
Chris@76
|
1726
|
Chris@316
|
1727 void
|
Chris@316
|
1728 TimeValueLayer::toXml(QTextStream &stream,
|
Chris@316
|
1729 QString indent, QString extraAttributes) const
|
Chris@6
|
1730 {
|
Chris@316
|
1731 SingleColourLayer::toXml(stream, indent,
|
Chris@316
|
1732 extraAttributes +
|
Chris@513
|
1733 QString(" colourMap=\"%1\" plotStyle=\"%2\" verticalScale=\"%3\" scaleMinimum=\"%4\" scaleMaximum=\"%5\" drawDivisions=\"%6\" ")
|
Chris@316
|
1734 .arg(m_colourMap)
|
Chris@316
|
1735 .arg(m_plotStyle)
|
Chris@445
|
1736 .arg(m_verticalScale)
|
Chris@445
|
1737 .arg(m_scaleMinimum)
|
Chris@513
|
1738 .arg(m_scaleMaximum)
|
Chris@513
|
1739 .arg(m_drawSegmentDivisions ? "true" : "false"));
|
Chris@0
|
1740 }
|
Chris@0
|
1741
|
Chris@11
|
1742 void
|
Chris@11
|
1743 TimeValueLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@11
|
1744 {
|
Chris@287
|
1745 SingleColourLayer::setProperties(attributes);
|
Chris@11
|
1746
|
Chris@445
|
1747 bool ok, alsoOk;
|
Chris@287
|
1748
|
Chris@287
|
1749 int cmap = attributes.value("colourMap").toInt(&ok);
|
Chris@287
|
1750 if (ok) setFillColourMap(cmap);
|
Chris@287
|
1751
|
Chris@11
|
1752 PlotStyle style = (PlotStyle)
|
Chris@11
|
1753 attributes.value("plotStyle").toInt(&ok);
|
Chris@11
|
1754 if (ok) setPlotStyle(style);
|
Chris@286
|
1755
|
Chris@286
|
1756 VerticalScale scale = (VerticalScale)
|
Chris@286
|
1757 attributes.value("verticalScale").toInt(&ok);
|
Chris@286
|
1758 if (ok) setVerticalScale(scale);
|
Chris@445
|
1759
|
Chris@513
|
1760 bool draw = (attributes.value("drawDivisions").trimmed() == "true");
|
Chris@513
|
1761 setDrawSegmentDivisions(draw);
|
Chris@513
|
1762
|
Chris@445
|
1763 float min = attributes.value("scaleMinimum").toFloat(&ok);
|
Chris@445
|
1764 float max = attributes.value("scaleMaximum").toFloat(&alsoOk);
|
Chris@445
|
1765 if (ok && alsoOk) setDisplayExtents(min, max);
|
Chris@11
|
1766 }
|
Chris@11
|
1767
|