Mercurial > hg > svgui
comparison layer/TimeValueLayer.cpp @ 6:02aaea1ffaf7
* Beginnings of session save code
* Add spline curve mode to time value layer
author | Chris Cannam |
---|---|
date | Thu, 12 Jan 2006 17:19:08 +0000 |
parents | 7af44e8578c8 |
children | 634324c6296e |
comparison
equal
deleted
inserted
replaced
5:37b110168acf | 6:02aaea1ffaf7 |
---|---|
15 #include "base/View.h" | 15 #include "base/View.h" |
16 | 16 |
17 #include "model/SparseTimeValueModel.h" | 17 #include "model/SparseTimeValueModel.h" |
18 | 18 |
19 #include <QPainter> | 19 #include <QPainter> |
20 #include <QPainterPath> | |
20 | 21 |
21 #include <iostream> | 22 #include <iostream> |
22 #include <cmath> | 23 #include <cmath> |
23 | 24 |
24 TimeValueLayer::TimeValueLayer(View *w) : | 25 TimeValueLayer::TimeValueLayer(View *w) : |
25 Layer(w), | 26 Layer(w), |
26 m_model(0), | 27 m_model(0), |
27 m_colour(Qt::black), | 28 m_colour(Qt::black), |
28 m_plotStyle(PlotLines) | 29 m_plotStyle(PlotConnectedPoints) |
29 { | 30 { |
30 m_view->addLayer(this); | 31 m_view->addLayer(this); |
31 } | 32 } |
32 | 33 |
33 void | 34 void |
84 else if (m_colour == QColor(255, 150, 50)) deft = 5; | 85 else if (m_colour == QColor(255, 150, 50)) deft = 5; |
85 | 86 |
86 } else if (name == tr("Plot Type")) { | 87 } else if (name == tr("Plot Type")) { |
87 | 88 |
88 *min = 0; | 89 *min = 0; |
89 *max = 3; | 90 *max = 4; |
90 | 91 |
91 deft = int(m_plotStyle); | 92 deft = int(m_plotStyle); |
92 | 93 |
93 } else { | 94 } else { |
94 | 95 |
115 } else if (name == tr("Plot Type")) { | 116 } else if (name == tr("Plot Type")) { |
116 switch (value) { | 117 switch (value) { |
117 default: | 118 default: |
118 case 0: return tr("Points"); | 119 case 0: return tr("Points"); |
119 case 1: return tr("Stems"); | 120 case 1: return tr("Stems"); |
120 case 2: return tr("Lines"); | 121 case 2: return tr("Connected Points"); |
121 case 3: return tr("Curve"); | 122 case 3: return tr("Lines"); |
123 case 4: return tr("Curve"); | |
122 } | 124 } |
123 } | 125 } |
124 return tr("<unknown>"); | 126 return tr("<unknown>"); |
125 } | 127 } |
126 | 128 |
159 } | 161 } |
160 | 162 |
161 bool | 163 bool |
162 TimeValueLayer::isLayerScrollable() const | 164 TimeValueLayer::isLayerScrollable() const |
163 { | 165 { |
166 // We don't illuminate sections in the line or curve modes, so | |
167 // they're always scrollable | |
168 | |
169 if (m_plotStyle == PlotLines || | |
170 m_plotStyle == PlotCurve) return true; | |
171 | |
164 QPoint discard; | 172 QPoint discard; |
165 return !m_view->shouldIlluminateLocalFeatures(this, discard); | 173 return !m_view->shouldIlluminateLocalFeatures(this, discard); |
166 } | 174 } |
167 | 175 |
168 QRect | 176 QRect |
302 if (m_view->shouldIlluminateLocalFeatures(this, localPos)) { | 310 if (m_view->shouldIlluminateLocalFeatures(this, localPos)) { |
303 SparseTimeValueModel::PointList localPoints = | 311 SparseTimeValueModel::PointList localPoints = |
304 getLocalPoints(localPos.x()); | 312 getLocalPoints(localPos.x()); |
305 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; | 313 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; |
306 } | 314 } |
307 | 315 |
316 paint.save(); | |
317 | |
318 if (m_plotStyle == PlotLines || | |
319 m_plotStyle == PlotCurve) { | |
320 paint.setRenderHint(QPainter::Antialiasing, true); | |
321 } | |
322 QPainterPath path; | |
323 | |
308 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); | 324 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); |
309 i != points.end(); ++i) { | 325 i != points.end(); ++i) { |
310 | 326 |
311 const SparseTimeValueModel::Point &p(*i); | 327 const SparseTimeValueModel::Point &p(*i); |
312 | 328 |
316 (max - min))); | 332 (max - min))); |
317 int w = m_model->getResolution() / zoomLevel; | 333 int w = m_model->getResolution() / zoomLevel; |
318 | 334 |
319 if (w < 1) w = 1; | 335 if (w < 1) w = 1; |
320 | 336 |
321 if (m_plotStyle == PlotCurve) { | 337 if (m_plotStyle == PlotLines || |
322 paint.setPen(QPen(QBrush(m_colour), 2)); | 338 m_plotStyle == PlotCurve) { |
339 paint.setPen(m_colour); | |
340 paint.setBrush(Qt::NoBrush); | |
323 } else { | 341 } else { |
324 paint.setPen(m_colour); | 342 paint.setPen(m_colour); |
343 paint.setBrush(brushColour); | |
325 } | 344 } |
326 paint.setBrush(brushColour); | |
327 | 345 |
328 if (m_plotStyle == PlotStems) { | 346 if (m_plotStyle == PlotStems) { |
329 paint.setPen(brushColour); | 347 paint.setPen(brushColour); |
330 if (y < origin - 1) { | 348 if (y < origin - 1) { |
331 paint.drawRect(x + w/2, y + 1, 1, origin - y); | 349 paint.drawRect(x + w/2, y + 1, 1, origin - y); |
334 } | 352 } |
335 paint.setPen(m_colour); | 353 paint.setPen(m_colour); |
336 } | 354 } |
337 | 355 |
338 if (illuminateFrame == p.frame) { | 356 if (illuminateFrame == p.frame) { |
357 | |
339 //!!! aside from the problem of choosing a colour, it'd be | 358 //!!! aside from the problem of choosing a colour, it'd be |
340 //better to save the highlighted rects and draw them at | 359 //better to save the highlighted rects and draw them at |
341 //the end perhaps | 360 //the end perhaps |
342 paint.setPen(Qt::black);//!!! | 361 |
343 paint.setBrush(Qt::black);//!!! | 362 //!!! not equipped to illuminate the right section in line |
344 } | 363 //or curve mode |
345 | 364 |
346 if (m_plotStyle != PlotCurve) { | 365 if (m_plotStyle != PlotCurve && |
366 m_plotStyle != PlotLines) { | |
367 paint.setPen(Qt::black);//!!! | |
368 paint.setBrush(Qt::black);//!!! | |
369 } | |
370 } | |
371 | |
372 if (m_plotStyle != PlotLines && | |
373 m_plotStyle != PlotCurve) { | |
347 paint.drawRect(x, y - 1, w, 2); | 374 paint.drawRect(x, y - 1, w, 2); |
348 } | 375 } |
349 | 376 |
350 if (m_plotStyle == PlotLines || m_plotStyle == PlotCurve) { | 377 if (m_plotStyle == PlotConnectedPoints || |
378 m_plotStyle == PlotLines || | |
379 m_plotStyle == PlotCurve) { | |
351 | 380 |
352 SparseTimeValueModel::PointList::const_iterator j = i; | 381 SparseTimeValueModel::PointList::const_iterator j = i; |
353 ++j; | 382 ++j; |
354 | 383 |
355 if (j != points.end()) { | 384 if (j != points.end()) { |
358 int nx = (q.frame - startFrame) / zoomLevel; | 387 int nx = (q.frame - startFrame) / zoomLevel; |
359 int ny = int(nearbyint(m_view->height() - | 388 int ny = int(nearbyint(m_view->height() - |
360 ((q.value - min) * m_view->height()) / | 389 ((q.value - min) * m_view->height()) / |
361 (max - min))); | 390 (max - min))); |
362 | 391 |
363 if (m_plotStyle == PlotLines) { | 392 if (m_plotStyle == PlotConnectedPoints) { |
393 | |
364 paint.setPen(brushColour); | 394 paint.setPen(brushColour); |
365 paint.drawLine(x + w, y, nx, ny); | 395 paint.drawLine(x + w, y, nx, ny); |
396 | |
397 } else if (m_plotStyle == PlotLines) { | |
398 | |
399 paint.drawLine(x + w/2, y, nx + w/2, ny); | |
400 | |
366 } else { | 401 } else { |
367 paint.drawLine(x, y, nx, ny); | 402 |
403 if (path.isEmpty()) { | |
404 path.moveTo(x + w/2, y); | |
405 } | |
406 | |
407 if (nx - x > 5) { | |
408 path.cubicTo(x + w, y, nx, ny, nx + w/2, ny); | |
409 } else { | |
410 path.lineTo(nx + w/2, ny); | |
411 } | |
368 } | 412 } |
369 } | 413 } |
370 } | 414 } |
371 | 415 |
372 | |
373 /// if (p.label != "") { | 416 /// if (p.label != "") { |
374 /// paint.drawText(x + 5, y - paint.fontMetrics().height() + paint.fontMetrics().ascent(), p.label); | 417 /// paint.drawText(x + 5, y - paint.fontMetrics().height() + paint.fontMetrics().ascent(), p.label); |
375 /// } | 418 /// } |
376 } | 419 } |
377 | 420 |
378 | 421 if (m_plotStyle == PlotCurve && !path.isEmpty()) { |
422 paint.drawPath(path); | |
423 } | |
424 | |
425 paint.restore(); | |
426 | |
427 // looks like save/restore doesn't deal with this: | |
428 paint.setRenderHint(QPainter::Antialiasing, false); | |
429 } | |
430 | |
431 QString | |
432 TimeValueLayer::toXmlString(QString indent, QString extraAttributes) const | |
433 { | |
434 return Layer::toXmlString(indent, extraAttributes + | |
435 QString(" colour=\"%1\" plotStyle=\"%2\"") | |
436 .arg(encodeColour(m_colour)).arg(m_plotStyle)); | |
379 } | 437 } |
380 | 438 |
381 | 439 |
382 #ifdef INCLUDE_MOCFILES | 440 #ifdef INCLUDE_MOCFILES |
383 #include "TimeValueLayer.moc.cpp" | 441 #include "TimeValueLayer.moc.cpp" |